数据量暂时在10来万,排序字段是几个索引里面的一个索引的二级索引
第一方案是比较传统的,
第二方案用了表变量,有说数据量大的时候应该用临时表,不知道这个量要多少。
感觉。。

DECLARE @pagesize int
DECLARE @pageindex int
DECLARE @docount bit
DECLARE @this_id INT

SET @this_id = 114
SET @docount = 3
SET @pagesize = 10
set @pageindex = 11983

 
--select count(*) from wn_pARTSnEWS where NEWSCLASSid=@this_id
 -- where NEWSCLASSid=@this_id

--方案一
BEGIN 
 
select TOP 10 * from wn_partsNews where partsNewsId not in (SELECT TOP 119830 PARTSNEWSID FROM WN_PARTSNEWS ORDER BY ADDTIME DESCORDER BY ADDTIME DESC
END
--方案二
begin
 
declare @indextable table(id int identity(1,1),nid int)
 
declare @PageLowerBound int
 
declare @PageUpperBound int

 
set @PageLowerBound=(@pageindex-1)*@pagesize --开始
 set @PageUpperBound=@PageLowerBound+@pagesize --结束

 
set rowcount @PageUpperBound

 
insert into @indextable(nid) select PARTSNEWSid from WN_PartsNews order by ADDTIME desc

 
select a.* from WN_PartsNews a,@indextable t where a.PARTSNEWSID=t.nid and t.id>@PageLowerBound and t.id<=@PageUpperBound order by t.id

end
GO



分页SQL语句的性能比较

相关文章:

  • 2021-12-28
  • 2022-01-07
  • 2021-06-11
  • 2022-12-23
  • 2021-11-13
  • 2021-12-27
  • 2021-11-03
  • 2021-11-01
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-30
  • 2022-03-04
相关资源
相似解决方案