(注意:所有命令不区分大小写)
1.创建数据库mydb
CREATE DATABASE mydb;
2.查看所有数据库
SHOW DATABASES;
3.查看创建的数据库
SHOW CREATE DATABASE mydb;
4.选择数据库
USE mydb;
5.创建数据表student
create table student(
name VARCHAR(10)COMMENT’名字’,
sex varchar(2)comment’性别’,
dianhua int(25)comment’电话’);
6.查看数据表new_class
use database mydb;
create table new_class(
name varchar(10)comment’姓名’,
class int(4)comment’班级’);
show tables like’%new%’;
7.查看数据表student相关信息
show table status from mydb like’%stu%’\G
8.修改数据表student
修改数据表名称
rename table student to student2;
或者 alter table student rename to student2;
或者 alter table student rename as student2;
修改表选项 alter table 表名 表选项 [=] 值;
9.查看表结构
查看数据表student2的字段信息
desc student2;
查看数据表的创建语句
show create table student2\G
查看数据表结构
show full columns from student2;
10.10.修改表结构
修改字段名 alter table student2 change sex home varchar(230);
修改字段类型 alter table student2 modify home char(23);
修改字段位置 alter table student2 modify dianhua int(25) after name;
新增字段 alter table student2 add birthplace int after dianhua;
删除字段 alter table student2 drop dianhua;
11.删除数据表student2;
drop table student2;
12.删除数据库mydb
drop database mydb;