申明:生平第一次写博客,相关条款了解不全,如有雷同之处请及时联系解决。本篇博客主要目的将自己的总结记载,如果有幸有大佬看到望指正不足。
一.分页语句
mysql: limit关键字的用法:limit(pageno-1)*pagesize,pagesize (当前页码-1)*页容量,页容量
sqlServer:
单表:
select * from (select *, ROW_NUMBER() OVER(Order by 排序的字段名) AS RowId from 表名) as b where RowId between pageNum(当前页码) and pageSize(页容量)
多表联查:
select * from(select *, ROW_NUMBER() OVER(order by t1.排序字段) as Row from (多表联查语句)as t1) as t2 where t2.Row between pageNum and pageSize
二.主键自增(通常设ID自增)
mysql:
1.创表语句AUTO_INCREMENT实现
create table if not exists userInfo (
id int PRIMARY KEY **AUTO_INCREMENT,**
name varchar(50) NOT NULL,
password varchar(50) NOT NULL
);
2.数据库可视化工具(navicat举例)
右键表格——》设计表——》左下角<自动递增勾选>
sqlServer:
1.创表语句 、
identity(seed, increment)
seed 起始值
increment 增量
create table student(
id int identity(1,1),
name varchar(100)
)
三.日期,时间函数
mysql:
1.返回当前时间,返回值以当前时区表达
CURTIME()、CURRENT_TIME()、CURRENT_TIME
2.返回当前时间和日期
NOW(),CURRENT_TIMESTAMP(),LOCALTIME(),LOCALTIMESTAMP()
sqlServer:
1.当前系统日期、时间
select getdate()
- dateadd 在指定日期加上一段时间,返回增加的日期值,例如:向日期加上5天
select dateadd(day,5,'2019-7-04') //返回:2019-7-09 00:00:00.000
3、datediff 返回两个指定日期的日期和时间的差
select datediff(day,'2004-09-01','2004-09-18') //返回:17
未完待续。。。。。。