1.修改表名
用法:
alter table 旧表名 rename 新表名;
alter table student rename students;
- 增加字段
用法:
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,身份证号码);