SQLServer 2000中的有效分页(限制)查询? [英] Efficient Paging (Limit) Query in SQLServer 2000?
问题描述
在SQLServer 2000中执行分页查询的最有效方法是什么?
What would be the most efficient way to do a paging query in SQLServer 2000?
分页查询"等同于在MySQL中使用LIMIT语句.
Where a "paging query" would be the equivalent of using the LIMIT statement in MySQL.
在这种情况下,存储过程是否会比任何基于集合的查询更有效?
Could a stored procedure be more efficient than any set based query in that case?
推荐答案
对大型结果集进行分页,获胜者正在使用RowCount.还有一个通用版本,可用于更复杂的查询. 但是要归功于 Jasmin Muharemovic :)
Paging of Large Resultsets and the winner is using RowCount. Also there's a generalized version for more complex queries. But give credit to Jasmin Muharemovic :)
DECLARE @Sort /* the type of the sorting column */
SET ROWCOUNT @StartRow
SELECT @Sort = SortColumn FROM Table ORDER BY SortColumn
SET ROWCOUNT @PageSize
SELECT ... FROM Table WHERE SortColumn >= @Sort ORDER BY SortColumn
本文包含完整的源代码.
The article contains the entire source code.
请阅读更新2004-05-05"信息. !
Please read the "Update 2004-05-05" information. !
这篇关于SQLServer 2000中的有效分页(限制)查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!