本文主要是介绍sqlserver2000分页正解,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
近段时间基于SqlServer2000进行了一些分页测试,在网上搜到的分页(非存储过程方式)方案中大部分都存在细节的完善,特将正确的细节补充如下:
网上搜到的分页实现如下:
FROM
Users
WHERE
(ID NOT IN (SELECT TOP (页大小*(页数-1)) ID FROM Users ORDER BY ID DESC))
ORDER BY
ID DESC
假定数据库中有42条记录,正确的逐页查询语句如下:
select top 10 id from d where d.id not in(select top 32 id from d order by id desc ) order by id desc --page 1(first page)
select top 10 id from d where d.id not in(select top 22 id from d order by id desc ) order by id desc --page 2
select top 10 id from d where d.id not in(select top 12 id from d order by id desc ) order by id desc -- page 3
select top 10 id from d where d.id not in(select top 2 id from d order by id desc ) order by id desc -- page 4
select top 2 id from d order by id desc -- page 5(last page)
这篇关于sqlserver2000分页正解的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!