sqlserver分页常用的有两种:
1.利用row_number
set statistics time on; -- 分页查询(通用型) select top pageSize * from (select row_number() over(order by sno asc) as rownumber,* from student) temp_row where rownumber>((pageIndex-1)*pageSize); set statistics time on; -- 分页查询第2页,每页有10条记录 select top 10 * from (select row_number() over(order by sno asc) as rownumber,* from student) temp_row where rownumber>10;
2.利用OFFSET FETCH NEXT
这个是sqlserver 2012及以上才能用
set statistics time on; -- 分页查询(通用型) select * from student order by sno offset ((@pageIndex-1)*@pageSize) rows fetch next @pageSize rows only; -- 分页查询第2页,每页有10条记录 select * from student order by sno offset 10 rows fetch next 10 rows only ;
EF分页:
query.Skip((pageIndex - 1) * pageSize).Take(pageSize)
在sqlserver profiler 调试中发现 EF CORE 的分页用的是 第二种OFFSET FETCH NEXT 。