mysql 数据库 命令行的操作——对表和字段的操作

一、对表的操作

1、查看所有表

show tables;

2、创建表

create table 表名(字段1 类型1 约束1 ,字段2 类型2 约束2);

3、修改表的名字

rename table  表名 to 新表名;

4、删除表

drop table 表名;

二、 对字段的操作

1、查询字段(表结构)

desc  表名;

2、增加字段

alter table 表名 add 字段名 类型 约束;

3、修改字段

alter table 表名 change  字段名 新字段名 类型 约束

4、删除字段

alter table 表吗名 drop 字段名

5、删除主键

需要先把主键的id改为普通的id不能自动增长,然后再删除主键

alter table students change id idint;
alter table students drop primary key;
alter table students change id idint auto_increment primary key notnull;

 

posted @ 2018-07-13 21:36  [流苏]  阅读(936)  评论(0编辑  收藏  举报