一、MYSQL数据库****
l 分类
数据定义语言(DDL)
Create 创建 alter修改 drop 删除
数据操纵语言(DML)
增加Insert 删除delete 更新update 查询select
数据控制语言(DCL)
分配grant 回收revoke 拒绝deny
l 数据类型
Bit 二进制
Date 日期时间
Time
Datetime
Decimal(p,s)定点数
Float(p,s) 4字节 浮点数
Double(p,s) 8字节
Tinyint 整数
Smallint
Int
Bigint
Char 文本
Varchar
text
Tinyint 整数
Smallint
Int
Bigint
l 语法
drop datebase 数据库 删除数据库
create datebase 数据库 创建数据库
Describe 数据表 查看表的基本结构
Show create table 数据表名 查看表详细结构
Show create table 数据表名 \G 查看表详细结构
Alter table 原来表名 to 新表名 修改表名
Alter table表名 chance 原来字段名 新字段名 新类型 修改字段名****
Alter table 表名 modify 字段名 新类型 修改字段数据类型****
Alter table 表名 add 新字段名 新类型 添加字段语法****
Alter table 表名 drop 字段名 删除字段语法****
Alter table 表名 add constraint 约束名称 primary key (列) 添加主键语法****
Alter table 表名 add constraint 约束名称 foreign key (列) references 引用表名(列) 添加外键语法****
Alter table 表名add constraint 约束名称check (列约束条件) 添加检查约束语法****
Alter table 表名 alter 列名 set default 默认值 添加默认值语法****
Alter table 表名 modify column 列名 类型 不能为空 auto_increment primary key 添加自动增长语法****
drop table 表名1,表名2 删除无关联数据表****
删除有关联数据表****
Alter table从表名称 drop foreign key 约束名 先解决关联关系****
Drop table 表1,表2 删除表****
Insert into 表名 values(值1,值2,...值) 所有列都插入值 列值同数,列值同序****
Insert into 表名(列1,列2,...列n) values(值1,值2,...值n)为特定列插入值 指定顺序,列值对应****
Insert into表名[(列1,列2,列n)] values (v1,v2,v3),(v31,v32,...v3n) 一次性插入多条记录****
Update 表名 set 列名=表达式 (例如 values,values+100) 修改全部数据****
Update 表名 set 列名=表达式 (例如 values,values+100) where 条件(列名=值) 修改特定数据****
Delete from 表名 where 列名=值 使用delete命令删除数据
Truncate table 表名 使用truncate table删除数据(不能使用where)****
简单查询****
Select 列名1,列名2,...列n from 表1,表2,表n where 列名=‘值’ group by(分组) group_by_list having 列名=‘值’ order by(排序) order_list[ASC | DESC] 语句查询
Select * (列1,列2,列3) from 表名 查询表的全部行和列****
Select 列名 AS‘别名’, 列名AS ‘玩家姓名’ from 表名
Distinct关键字 作用:消除结果集中的重复行****
Select distinct 列名 from 表名
Limit 关键字 作用:指定结果集中数据的显示范围****
Select * from 表名 limit [下标,数量(多少条)] 显示特定数据
Select * from 表名 limit [数量(多少条)] 从第一条数据开始显示多少条数据
Select *(列名) from 表名 where 条件表达式(列=’值1’)
Select *(列名) from 表名 where 条件表达式(列=’值1’)and (列>值)
Select *(列名) from 表名 where 条件表达式(列=’值1’)or (列=值)
模糊查询****
Select *(列名) from 表名 where 条件表达式(列>=’值1’)and (列<=值)
Select *(列名) from 表名 where between 范围1 and 范围2
‘_’一个字符 %任意长度 []指定范围内 [^]不在括号中
Select (列名) from 表名 like ‘值%’ 查询所有值的信息***
Select (列名) from 表名 not like ‘值%’ 查询所有非值的信息***
Select (列名) from 表名 where 列名 is Null 查询所有为空的信息***
Select (列名) from 表名 where 列名 is Not Null 查询所有不为空的信息***
对查询结果进行排序****
单列排序****
Select * from 表名 where 列=’值1’ order by ‘列’ ASC 升序
Select * from 表名 where 列=’值1’ order by ‘列’ DESC 降序
多列排序****
排序依据 排序方式 优先级
Select * from 表名 order by 列1 ASC, 列2 DESC