sqlserver分页的两种写法分别介绍
时间:2021-07-01 10:21:17
帮助过:36人阅读
第一种是最传统的写法,用存储过程中的变量作为分页的乘数
代码如下:
[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
--SQL Server2005以后的分页语句
代码如下:
[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
您可能感兴趣的文章:
- 真正高效的SQLSERVER分页查询(多种方案)
- oracle,mysql,SqlServer三种数据库的分页查询的实例
- sqlserver2005使用row_number() over分页的实现方法
- sqlserver 三种分页方式性能比较[图文]
- sqlserver 高性能分页实现分析
- sqlserver 千万数量级分页存储过程代码
- sqlserver 存储过程分页(按多条件排序)
- SQL Server 2012使用Offset/Fetch Next实现分页数据查询