Home  >  Article  >  Database  >  对SQLServer中有主键的表tb,写出效率较高的翻到第二页的sql查询

对SQLServer中有主键的表tb,写出效率较高的翻到第二页的sql查询

WBOY
WBOYOriginal
2016-06-07 15:39:451544browse

declare @pageSize int --返回一夜的记录数 declare @CurPage int --页号(第几页) declare @Count int declare @id int set @pageSize=10 set @CurPage =1 --定位 if @CurPage = -1 begin --最后一页 set rowcount @pageSize select @id=newsID from newsT

declare @pageSize int      --返回一夜的记录数

declare @CurPage int   --页号(第几页)

declare @Count int

declare @id int

set @pageSize=10
set @CurPage =1

--定位
if @CurPage = -1
begin
 --最后一页
 set rowcount @pageSize
 select @id=newsID from newsTemp   order by newsID
end

if @CurPage > 0
begin
 set @Count = @pageSize * (@CurPage -1) + 1
 set rowcount @Count
 select @id=newsID from newsTemp   order by newsID desc
end

--返回记录
set rowcount @pageSize
select * from newsTemp where newsID

set rowcount 0

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn