SQL Server 分页的两种写法分别介绍
2022-11-12 09:50:34
内容摘要
这篇文章主要为大家详细介绍了SQL Server 分页的两种写法分别介绍,具有一定的参考价值,可以用来参考一下。
对此感兴趣的朋友,看看idc笔记做的技术笔记!第一种是最传统的写法,用
文章正文
这篇文章主要为大家详细介绍了SQL Server 分页的两种写法分别介绍,具有一定的参考价值,可以用来参考一下。
对此感兴趣的朋友,看看idc笔记做的技术笔记!
第一种是最传统的写法,用存储过程中的变量作为分页的乘数代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <code> [c-sharp] view plaincopyprint?create proc p_paged1 @pageSize int,@currentPage int as select top (@pageSize) * from student where id not in (select top (@pageSize*(@currentPage-1)) id from student) go exec p_paged1 2,3 create proc p_paged1 @pageSize int,@currentPage int as select top (@pageSize) * from student where id not in (select top (@pageSize*(@currentPage-1)) id from student) go exec p_paged1 2,3 </code> |
代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 | <code> [c-sharp] view plaincopyprint?create proc p_paged2 @pageStart int, @pageEnd int as select * from (select *,row_number() over(order by id desc) as rnum from student) t where t.rnum between @pageStart and @pageEnd go exec p_paged2 5,10 </code> |
注:关于SQL Server 分页的两种写法分别介绍的内容就先介绍到这里,更多相关文章的可以留意
代码注释