1》 修改表名
alter table 旧表名 rename to 新表名;
-- 示例: 把tb_temp1的名字修改成temp1
-- alter table tb_temp1 rename to temp1;
2》 修改字段的数据类型
alter table 表名 modify 字段名 新的数据类型 [约束];
-- 示例: 把 tb_temp1表的c1字段的数据类型修改成text
-- alter table tb_temp1 modify c1 text ;
3》 修改字段名
alter table 表名 change 旧字段名 新字段名 数据类型;
-- 示例:把tb_temp1表的c1 改成 cc1
-- alter table tb_temp1 change c1 cc1 text;
4》 添加字段
alter table 表名 add 新字段名 数据类型 约束
[first|after 已经存在字段名];
-- 示例:在tb_temp1表中添加int cc2
alter table tb_temp1 add cc2 int;
5》 删除字段
alter table 表名 drop 字段名;
6》 修改字段的排列位置
alter table 表名 modify 字段名 数据类型 first | after 已经存在的列名;
-- 让 cc3列在第一个显示
alter table tb_temp1 modify cc3 varchar(30) first;
alter table tb_temp1 modify cc3 varchar(30) after cc1;
desc tb_temp1; -- 查看表结构