一、修改
--alter table 旧表名 rename as 新表名; --修改表名
alter table old rename as new;
--alter table 表名 add 字段名 列属性; --增加表的字段
alter table student add age int(10);
--alter table 表名 modify 字段名 列属性; 修改表的字段(重命约束)
alter table student modify age varchar(11);
--alter table 表名 change 旧字段名 新字段名 列属性; 修改表的字段(重命名字)
alter table student change age age1 int(11);
结论:
change用来字段重命名,不能修改字段类型和约束。
modify不用来字段重命名,只能修改字段类型和约束
二、删除
--alter table 表名 drop 字段名;删除表字段
alter table student drop age1
--drop table 表名; 删除表
drop table if exists student;
所有的创建和删除操作尽量加上判断,以免报错
三、总结注意
- 字段名最好使用``包裹;
- 注释:–,/**/
- 关键字大小写不敏感,建议写小写;
- 所有的符号全部用英文;