set statistics time on set statistics io on set statistics profile on; with #pager as ( select ID,Title,NTILE(8666) OVER(Order By ID) as pageid from Article_Detail ) select ID,Title from #pager where pageid=50 set statistics profile on;
在 Sql Server 2000 之后的版本中,ROW_NUMBER() 这种分页方式一直都是很不错的,比起之前的游标分页,性能好了很多,因为 ROW_NUMBER() 并不会引起全表扫表,但是,语法比较复杂,并且,随着页码的增加,性能也越来越差。 语法 : ROW_NUMBER ( ) OVER ( [ PARTITION BY value_expression , ... [ n ] ] order_by_clause ) 测试中用到的 Sql 语句:
复制代码 代码如下:
dbcc freeproccache dbcc dropcleanbuffers set statistics time on set statistics io on set statistics profile on; with #pager as ( select ID,Title,ROW_NUMBER() OVER(Order By ID) as rowid from Article_Detail ) select ID,Title from #pager where rowid between (15 * (50-1)+1) and 15 * 50 set statistics profile off;
dbcc freeproccache dbcc dropcleanbuffers set statistics time on set statistics io on set statistics profile on; select ID,Title from Article_Detail order by id OFFSET (15 * (50-1)) ROW FETCH NEXT 15 rows only set statistics profile off;