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;