外键的级联操作:
- restrict : ( 默认 ) 限制删除,抛出异常
- cascade : (级联)如果主键被删掉,则从表中相应的记录也被删掉
- set null : 将外键设置为空
- no action : 什么都不做
关联查询:
- 内连接:只满足连接条件的数据
- 左连接:满足连接条件的数据和左边剩余的数据
- 右连接:满足连接条件的数据和右表剩余的数据
- 外连接:两个表的并集,左连接 U 右连接
Mysql内置性能工具的使用:
set profiling = 1
执行sql语句
show profiles
常用的内置函数
- ascii() --返回字符的sacii码
- char() --查看ascii码对应的字符值
- concat(var1,var2,var3) --字符串拼接
- length(str) --返回字符长度
- substring(str,start,len) --字符串截取
- trim() ltrim() rtrim() --字符串去空格
- space(n) --返回n个空格组成的字符串
- replace(str,old,new) --str中的old用new替换
- lower() --返回小写格式
- upper() --返回大写格式
- abs() --返回绝对值
- mod(m,n) --m%n
- floor() --地板值
- ceiling() --天花板值
- round(n,d) --n取四舍五入,d为小数点后的位数,默认值为0
- pow(x,y) --x的y次幂
- PI() --圆周率
- rand() --0到1.0之间的浮点数
- year(date) --返回年份
- month(date) --返回月份
- day(date) --返回日期值
- hour(date)
- minute(date)
- second(date)
- date_format(date,format) --按格式输出日期
- current_date() --当前日期
- current_time() --当前时间
- now() --当前日期+时间
- select now() + interval 1 month