MySQL数据表基本操作

查看表结构

desc 表名

 MySQL数据表基本操作

show create table 表名\G;  查看表详细结构

 MySQL数据表基本操作

 

修改数据表

修改表名

alter table 旧表名 rename [to] 新表名;     to带不带均可

 MySQL数据表基本操作

 MySQL数据表基本操作

 MySQL数据表基本操作

修改字段的数据类型

alter table 表名 modify 字段名 数据类型;

 MySQL数据表基本操作

MySQL数据表基本操作

添加字段

alter table 表名 add 新字段名 类型 约束条件  [ first | after 已存在字段名];

 MySQL数据表基本操作

删除字段

alter table 表名 drop 字段名;

 MySQL数据表基本操作

修改字段的排列位置

alter table 表名 modify 字段名 字段类型 [ first | after 字段名]

MySQL数据表基本操作

 

更改表的存储引擎

 alter table 表名 engine=更改后的引擎名 ;

 MySQL数据表基本操作

删除外键

 alter table 表名 drop foreign key 外键名; MyISAM存储引擎不支持外键

MySQL数据表基本操作 

 MySQL数据表基本操作

MySQL数据表基本操作

 删除数据表

drop table if exists 1,表2.....n; 删除未被外键关联的表

 MySQL数据表基本操作

如果表是被外键关联的主表则需要先删除外键再删除主表

 MySQL数据表基本操作

MySQL数据表基本操作

MySQL数据表基本操作