修改表
1、添加字段:
alter table 表名add [column] 字段名 数据类型 [位置] ;
2、删除字段:
alter table 表 drop [column] 字段名 ;
3、修改字段(改名):
alter table 表 change [column] 原字段名 新字段名 数据类型 …;
4、修改字段数据类型:
alter table 表 modify 字段名 数据类型;
5、修改引擎:
alter table 表名 engine=引擎名;
6、修改表名:
alter table 表名 rename to 新表名 ;
7、将表移动到其他数据库
alter table 表名 rename to 另一个数据库名.表名;
主键
添加主键
alter table 表名 add primary key(id);
删除主键
alter table 表名 drop primary key;
外键
添加外键
alter table 从表 add foreign key(公共字段) references 主表(公共字段);
删除外键
alter table 表名 drop foreign key `外键名`;
索引
创建唯一索引
alter table 表名 add uniqe [index] 索引名(字段名);
创建普通索引
alter table 表名 add index 索引名(字段名);