sqlserver分頁的兩種寫法分別介紹
更新時間:2012年11月23日 09:07:28 作者:
本文將介紹sql server傳統(tǒng)的寫法與SQL Server2005以后的分頁語句需要了解的朋友可以參考下
第一種是最傳統(tǒng)的寫法,用存儲過程中的變量作為分頁的乘數(shù)
[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
復(fù)制代碼 代碼如下:
[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以后的分頁語句
復(fù)制代碼 代碼如下:
[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
相關(guān)文章
調(diào)整SQLServer2000運(yùn)行中數(shù)據(jù)庫結(jié)構(gòu)
這篇文章主要介紹了調(diào)整SQLServer2000運(yùn)行中數(shù)據(jù)庫結(jié)構(gòu),十分實(shí)用的一個功能,這里推薦給大家,有需要的小伙伴可以參考下。2015-04-04
關(guān)于SQL Server數(shù)據(jù)庫中的用戶權(quán)限和角色管理功能實(shí)現(xiàn)
在本文中,我們介紹了在SQL Server中創(chuàng)建用戶、分配權(quán)限和管理角色的基礎(chǔ)知識,請記住定期審查和更新用戶權(quán)限,以符合您組織的安全政策和數(shù)據(jù)訪問要求,這篇文章主要介紹了關(guān)于SQL Server數(shù)據(jù)庫中的用戶權(quán)限和角色管理,需要的朋友可以參考下2024-03-03

