修改表名rename
Alter table 旧表名 rename 新表名;
修改字符段modify
alter table 表名 modify 字段名 数据类型 ;
修改字段名change
alter table 表名 change 旧字段名 新字段名 新数据类型;
添加字段add (first 在列队中的第一个 after 在…之后)
alter table 表名 add 新字段名 数类型 ;
删除字段 drop
alter table 表名 drop 字段
修改列的排序modify (first 在列队中的第一个 after 在…之后)
Alter table 表名 modify 字段名 数据类型 after 字段名2;
更改表的存储引擎 engines=
Alter table 表名 engines=更改后的存储引擎
创建无约束表
alter table 表名 modify 新字段名 数类型 ;
添加约束
单列主键primary key
alter table 表名 modify 字段名 数据类型 primary key
多列主键
alter table 表名 add primary key (a,b);
非空约束
alter table 表名 modify 列 int not null;
唯一约束
alter table 表名 modify 列 int unique ;
默认值
alter table 表名 modify 列 int default 123;
主键自增
alter table 表名 modify 列 int primary key auto_increment;
外键约束
alter table 表名 add foreign key (本表的主键) references 外表名(主键)
删除约束
单列主键
alter table 表名 drop primary key;
多列主键
alter table 表名 drop primary key ;
非空约束
alter table 表名 modify dc int ;
唯一约束
alter table 表名 drop key 列;
默认值
alter table 表名 column 列名 drop default;
主键自增
alter table 表名 modify 列名 int;
外键约束
alter table 表名 drop foreign key 外键约束名;