SQL Server的三种分页方式

来源:互联网 发布:天津市网络教育平台 编辑:程序博客网 时间:2024/04/30 03:23

目前常见的三种SQL分页方式:


 --top not in方式select top 条数 *  from tablenamewhere Id not in (select top 条数*页数  Id from tablename)--ROW_NUMBER() OVER()方式  select * from (     select *, ROW_NUMBER() OVER(Order by Id ) AS RowNumber from tablename  ) as b  where RowNumber BETWEEN 当前页数-1*条数 and 页数*条数   --offset fetch next方式--SQL2012以上的版本才支持select * from tablename order by Id offset 页数 row fetch next 条数 row only 



分析:在数据量较大时

top not in方式:查询靠前的数据速度较快

ROW_NUMBER() OVER()方式:查询靠后的数据速度比上一种较快

offset fetch next方式:速度稳定,优于前2种,但sql版本限制2012及以上才可使用

0 0
原创粉丝点击