1.【新建】create
(1)新建数据库:create database + 数据库名
例:
create database hhy;#创建hhy数据库
show databases;#查看数据库
(2)新建数据表:create table + 数据表名(
字段名 数据类型,
字段名 数据类型,
.......
字段名 数据类型
);
例:
create table student(
id_stu int primary key ,
stu_name char(12) not null,
stu_age int not null);#创建数据表student
#创建一个和student结构相同的数据表:create table 表1 like 表2
create table hhy.st like hhy.stduent;
2.【查看】
(1)查看全部数据表——show tables
(2)查看表结构——desc + 数据库.数据表
desc hhy.st;
3.【清空/删除】
(1)清空数据表:truncate table + 数据表
truncate table stduent;#清空数据表中的数据(不影响表结构)
(2)删除数据表:drop table + 数据表
drop table stduent;
(3)删除数据库:drop schema + 数据库名
drop schema hhy;
4.【修改】alter table
(1)修改数据表名称:alter table 原表 rename 修改
alter table student rename stu;
(2)修改字段类型:alter table 数据表名 modify 字段 改类型
alter table stu modify stu_name varchar(9);
(3)修改字段名称和类型:alter table 数据表名 change 原字段 改字段 改类型
alter table stu change stu_name student_name char(9);
(4)添加字段:alter table 数据表 add 添加字段 enum(' ')
alter table stu add num enum('');
(5)删除字段:alter table 数据表 drop column 删除字段
alter table stu drop column num;