函数
字符串函数
数值函数
mod就是取余
日期函数
流程函数
约束
外键约束
删除更新\外键
多表查询
多表关系
一对多
多对多
一对一
多表查询
内连接
select e.name d.name from emp e join dept d on e.id = d.id;
外连接
select emp.*, d.name from emp left join tmp on emp.id = tmp.id
select emp.*, d.* from emp right join tmp on emp.id = tmp.id
自连接
联合查询
select * from emp where salary < 5000
union
select * from emp where age > 50;
子查询
标量子查询
select * from emp where dept_id = (select id from dept where name = '销售部');
select * from emp where entrydata >= (select entrydata from emp where name = '防冻呗');
列子查询
select * from emp where id = (select id from dept where name = '销售部' or name = '市场部')
select * from emp where salary >= all(select min(salary) from emp where id = (select id from where name = '财务部'));
行子查询
select * from emp where (salary, managerid) = (select salary, managerid from emp where name = '张无忌');
表子查询
事务
事务操作
当 SET @@autocommit=0之后,所有的修改都必须再加上commit才能成功执行;
事务的四大特性
并发事务引发的问题
事务隔离级别
set session transaction isolation level read uncommitted