zoukankan      html  css  js  c++  java
  • 表,字段处理详细, 创建用户 ,用户管理 表关系

    ---恢复内容开始---

    1.修改表名

    alter table t1 rename t2;

    2.修改表里字段类型

    alter table t1 modify name  char(5);

    3.修改表里字段名

    alter table  t1 change  name  age int;

    4.复制表

    create table t2 like t1;  复制表的结构约束 无数据

    create table t2 select *from t1; 复制表的数据与结构 无约束

    create  table t2 select*from t1 where 1=2(假命题) 复制表的结构 

    5.请空表

    truncate 他

    6.添加

    alter  table t1 add  name char(5) not null   first

     alter  table t1 add  name char(5) not null   after  age

    7.删除字段名

    alter  table t1  drop name;

    用户管理

    创建用户

    create user  zero@localhost  identified by'zero';

    创建权限

    grant all  on db1.* to zero@localhost  with  grant  option;

    一起创建

    grant all on db1.* to zero@localhost  identified by'zero' 

    撤销权限

    revoke delete on db1.* from zero@localhost;

    修改密码

    set password for zero@localhost = password('123');

    删除用户

    drop user zero@localhost

    表关系

    on update cascade # 设置级联

    on delete cascade不设置级联只能先删除依附表一对多的多的内容,多对多都不能删除要先删关系表

    多对一

    create table school (id int primary key,name char)

    crsete table student(id int primary key, name char, nid int,foreign key (nid) references school(id));

    一对一

    create table husband(id int primary key, name char);

    createtable  wife (id int primary key, nid int unique,name char,foreign key(nid) references wife(id));

    一对一注意外键对应字段设置唯一键

    外键不为主键,必须为对方主键,数据类型要一致

    多对多

    create table student(id int primary key,name char );

    create table lesson(id int primary key,name char(5));

    create table xuanke(id int primary key, nid1 int,nid2 int,foreign key(nid1) references student(id),foreign key(nid2) references lesson(id))

    关键是关系表建立

    ---恢复内容结束---

  • 相关阅读:
    SqlServer数据库SQL语句(超详细)
    oracle sql语句
    MySQL常用SQL语句
    一路走来,风雨兼程,也谈笑风生
    个人第五次——测试别人的项目
    团队第五次——Alpha2的发布
    团队第四次——Alpha版本的发布
    团队第三次——系统设计
    第四次作业 结对编程
    团队第二次作业——需求分析
  • 原文地址:https://www.cnblogs.com/wrqysrt/p/10246636.html
Copyright © 2011-2022 走看看