From:http://www.ljnid.cn/?id=145
先来一段代码:
WITH OrderedOrders AS
(SELECT *,
ROW_NUMBER() OVER (order by [id])as RowNumber --id是用来排序的列
FROM table_info ) --table_info是表名
SELECT *
FROM OrderedOrders
WHERE RowNumber between 50 and 60;
在windows server 2003, sql server 2005 CTP,P4 2.66GHZ,1GB 内存下测试,执行时间0秒 ,表中数据量230万
接下来大批量的数据查询性能瓶颈就在count了,不知道sql server 2005在这方面有没有什么改进.
附另一种方法:
SELECT *
FROM (select *,ROW_NUMBER() Over(order by id) as rowNum from table_info ) as myTable
where rowNum between 50 and 60;
参考:
SQL Server 2005中的T-SQL增强
http://info.hustonline.net/document/doc.aspx?ID=1744
SQL Server 2005新功能-TSQL
http://play.365pop.net/InfoView/Article_80580.html
<script type="text/JavaScript"> var alimama_pid="mm_10046688_140306_139836"; var alimama_titlecolor="0000FF"; var alimama_descolor ="000000"; var alimama_bgcolor="FFFFFF"; var alimama_bordercolor="E6E6E6"; var alimama_linkcolor="008000"; var alimama_sizecode="12"; var alimama_width=468; var alimama_height=60; var alimama_type=2; </script> <script src="http://p.alimama.com/inf.js" type="text/javascript"> </script>