DDL
数据定义语言,用来定义数据库对象
数据库操作
创建数据库: create database [if not exists] 数据库名;
使用数据库: use database 数据库名;
删除数据库: drop database [if exists] 数据库名;
查看所有数据库: show databases;
查看当前所在数据库: select database();
查看指定库的建库语句: show create database 数据库名;
库中表操作
创建表: create table 表名(字段名1 字段类型, 字段名2 字段类型, ...);
删除表: drop table [if exists] 表名;
修改表: 添加字段: alter table 表名 add (字段名1 字段类型, 字段名2 字段类型,...);
删除字段: alter table 表名 drop 字段名;
修改表名: alter table 表名 rename to 新表名;
rename table 表名 to 新表名;
修改字段名: alter tabel 表名 change 旧字段名 新字段名 字段类型;
修改字段类型: alter table 表名 modify 字段名 新字段类型;
查看所有表: show tables;
查看表结构: desc table 表名;
查看创建表语句: show create table 表名;
DML
数据操作语言,用来对数据库表中的数据进行增删改
添加数据
insert into 表名 (字段名1, 字段名2, ...) values (值1, 值2, ...);
删除数据
delete from 表名 [where 条件];
修改数据
update 表名 set 字段1 = 值1, 字段2 = 值2, ...[where 条件];