DROP DATABASE [IF EXISTS] 数据库名;
drop database student;
1
2
1
2
5.建表
5.建表
CREATE TABLE [IF NOT EXISTS] tablename(字段名 字段类型,....)[charset=utf8];
create table if not exists student(id integer,name varchar(20),age integer);
charset=utf8;
1
2
3
4
1
2
3
4
6.显示当前数据库下所有的表
SHOW TABLES;
1
1
7.显示建表语句
SHOW CREATE TABLE 表名;
show create table student;
1
2
1
2
8.为表中增加列
ALTER TABLE 表名 ADD 字段名 字段类型;
ALTER TABLE 表名 ADD (字段名 字段类型,...)
alter table student add sex varchar(5);
1
2
3
1
2
3
9.修改列定义
ALTER TABLE 表名 MODIFY 字段名 新字段类型;
alter table student modify sex text;
ALTER TABLE 表名 CHANGE 旧列名 新列名 新列定义;
alter table student change sex 性别 varchar(5);
modify无法修改列名,change可以修改列名
1
2
3
4
5
6
7
8
1
2
3
4
5
6
7
8
10.删除列
ALTER TABLE 表名 DROP 列名;
alter table student drop 性别;