(本人菜鸟一枚,如有不对,轻轻喷!!!)
1、Limit用法
limit接受一个或两个数字参数。
1.1 如果是两个参数,第一个参数是指返回记录行的偏移量,第二个参数是指返回记录的行数。
ex: SELECT * FROM tablename LIMIT 5,10;//检索记录行6-10;
1.2 如果只给定一个参数,则表示返回最大的行数
ex: SELECT * FROM tablename LIMIT 5;//检索前5个记录行,相当于0,n
1.3 LIMIT 1;
在某些情况下,如果明知道查询结果只有一个,SQL语句中使用LIMIT 1会提高效率。适用于查询结果为1条(也可以为0条)会导致全表扫描的SQL语句
2、count(1)
count(1)、count(2)和count(*)是一样的
而count(column)和count(*)是不一样的
3、UNSIGNED
增加数据长度。
ex:假如id的长度为20,则id UNSIGNED则为20*2的长度
4、coalesce()函数
coalesce():返回参数中的第一个非空表达式(从左向右依次类推)
ex:
select coalesce(null,2,3)//return 2;
select coalesce(1,2,3)//reutrn 1;
select coalesce(null,null,3)//return 3;
5、查看表当前的auto_increment
表的基本数据是存放在MySQL的information_schema库的tables表中,我们可以使用sql查出
select auto_increment from information_schema.tables where table_schema='db name' and table_name='table name';
修改表auto_increment
alter table tablename auto_increment=NUMBER;