MySQL数据表基本操作
查看表结构
desc 表名
show create table 表名\G; 查看表详细结构
修改数据表
修改表名
alter table 旧表名 rename [to] 新表名; to带不带均可
修改字段的数据类型
alter table 表名 modify 字段名 数据类型;
添加字段
alter table 表名 add 新字段名 类型 约束条件 [ first | after 已存在字段名];
删除字段
alter table 表名 drop 字段名;
修改字段的排列位置
alter table 表名 modify 字段名 字段类型 [ first | after 字段名];
更改表的存储引擎
alter table 表名 engine=更改后的引擎名 ;
删除外键
alter table 表名 drop foreign key 外键名; MyISAM存储引擎不支持外键
删除数据表
drop table if exists 表1,表2,.....表n; 删除未被外键关联的表
如果表是被外键关联的主表则需要先删除外键再删除主表