Mysql下修改表(alter)

1.修改表名
用法:
alter table 旧表名 rename 新表名;

alter table student rename students;
  1. 增加字段
    用法:
    alter table 表名 字段名 数据类型[完整性约束条件];
alter table teacher add sge tinyint;

3.删除字段
用法:
alter table 表名 drop 字段名;

alter table teacher drop 年龄;

4.修改字段
用法:
alter table 表名 modify 字段名 数据类型[完整性约束条件…];
alter table 表名 change 旧字段名 新字段名 旧字段类型[完整性约束条件…]
alter table 表名 change 旧字段名 新字段名 新数据类型[完整性约束条件…]

alter table teacher modify 年龄 int;
alter table teacher change 年龄 age int;
alter table teacher change age 年龄 tinyint;

修改表的存储引擎

alter table service  engine=innodb;  

增加约束(针对已有的主键增加auto_increment)

alter table teacher modify id int not null auto_increment;

增加复合主键

alter table student add primary key(sid,身份证号码);	

猜你喜欢

转载自blog.csdn.net/wana_one_gy/article/details/82713329