1.添加单列
ALTER TABLE tbl_name ADD [COLUMN] col_name column_definition [FIRST | AFTER col_name];
2.删除列
ALTER TABLE tbl_name DROP [ COLUMN ] col_name;
3.添加主键约束
ALTER TABLE tbl_name ADD [ CONSTRAINT [symbol] ] PRIMARY KEY [index_type] (index_col_name, ...);
4.添加唯一约束
ALTER TABLE tbl_name ADD [ CONSTRAINT [symbol] ] UNIQUE KEY [ INDEX | KEY ] [index_name] [index_type] (index_col_name, ...)
5.添加外键约束
ALTER TABLE tbl_name ADD [ CONSTRAINT [symbol] ] FOREIGN KEY [ index_name ] (index_col_name, ...) reference_definetion;
6.添加/删除默认约束
ALTER TABLE tbl_name ALTER [COLUMN] col_name {SET DEFAULT literal |DROP DEFAULT};
7.删除主键约束
ALTER TABLE tbl_name DROP PRIMARY KEY;
8.删除唯一约束
ALTER TABLE tbl_name DROP {INDEX|KEY} index_name ;
9.删除外键约束
ALTER TABLE tbl_name DROP FOREIGN KEY fy_symbol;
10.修改列定义
ALTER TABLE tbl_name MODIFY [COLUMN] col_name column_definition [FIRST|AFTER col_name];
11.修改列名称
ALTER TABLE tbl_name CHANGE [COLUMN] old_col_name new_col_name column_definition [FIRST|AFTER col_name];
12.数据表更名
方法一
ALTER TABLE tbl_name RENAME [TOIAL] new_tbl_name;
方法二
RENAME TABLE tbl_name TO new_tbl_name [tbl_name2 TO new_tbl_name2];
13.小结
修改数据表:
针对字段的操作:添加/删除字段、修改列定义、修改列名称等
针对约束的操作:添加/删除各种约束
针对数据表的操作:数据表更名(两种方式)