DML:
数据操作语言,增删改查数据,包括insert,delete,update,select
添加语句
insert into 表名 (字段名,字段名,字段名...) values (参数,参数,参数...)
批量添加
insert into 表名 (字段列表) values (参数列表),(参数列表),(参数列表)...
删除语句
delete from 表名 where 字段名 = 参数 #where表示条件,可有可无,下同
truncate 表名称; 删除整张表的数据
批量删除
delete from 表名 where 字段名 in (参数,参数,参数...)
delete from 表名 where 字段名 = 参数 or 字段名 = 参数 or ...
查询语句
select 字段列表 from 表名 where ...
批量查询
select 字段列表 from 表名 where in ()
select 字段列表 from 表名 where 字段名 = 参数 or 字段名 = 参数 or ...
修改语句
update 表名 set 字段名1 = 参数1,字段名2 = 参数2,字段名3 = 参数3,... where ...
批量修改
#修改为相同数据
update 表名 set 字段名1 = 参数1,字段名2 = 参数2,字段名3 = 参数3,...... where 字段名 in(参数,参数,参数...)
update 表名 set 字段名1 = 参数1,字段名2 = 参数2,字段名3 = 参数3,...... where 字段名 = 参数 or 字段名 = 参数 or...
DDL:
数据定义语言,定义库,表结构,包括creat、drop、alter等
数据库操作
1、查看所有数据库
show databases;
2、指定使用某个数据库
use 数据库名;
3、创建数据库
create database 数据库名;
create database 数据库名 charset 'utf8'; #在mysql中字符集名称不要使用utf-8
create database 数据库名 charset 'gbk';
4、删除数据库
drop database 数据库名;
表格操作
5、查看某个库下的所有表格
show tables from 数据库名
6、创建表格
create table 表名(
字段名1 数据类型,
字段名2 数据类型,
...
)
7、删除表格
drop table 【数据库名】 表名称; #【】中的可有可无,下同
8、查看某个表结构
describe 【数据库名】 表名称;
desc 【数据库名】 表名称
9、增加一列
alter table 表名称 add【column】字段名 数据类型;
alter table 表名称 add【column】字段名 数据类型 first;
alter table 表名称 add【column】字段名 数据类型 after 另一个字段名;
10、删除一列
alter table 表名称 drop 【column】字段名
11、修改列数据类型
alter table 表名称 modify 【column】字段名 行数据类型
12、修改列名
alter table 表名称 change 【coulumn】旧字段名 新字段名 新数据类型
13、修改列的位置
alter table 表名称 modify 字段名 数据类型 first;
alter table 表名称 modify 字段名 数据类型 after 另一个字段名;
14、修改表名称
alter table 旧表名称 rename 新表名称;
rename table 旧表名称 to 新表名称;