国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > 綜合 > 正文

發(fā)布一個高效的數(shù)據(jù)分頁的存儲過程 可以輕松應(yīng)付百萬數(shù)據(jù)

2024-07-21 02:12:05
字體:
供稿:網(wǎng)友

create procedure pagetest  --用于翻頁的測試
--需要把排序字段放在第一列

 (
  @firstid nvarchar(20)=null,  --當(dāng)前頁面里的第一條記錄的排序字段的值
  @lastid nvarchar(20)=null,  --當(dāng)前頁面里的最后一條記錄的排序字段的值
  @isnext bit=null,    --true 1 :下一頁;false 0:上一頁
  @allcount int output,   --返回總記錄數(shù)
  @pagesize int output,   --返回一頁的記錄數(shù)
  @curpage int     --頁號(第幾頁)0:第一頁;-1最后一頁。
  )

as

if @curpage=0
 begin
  --統(tǒng)計總記錄數(shù)
  select @allcount=count(productid) from product_test
  
  set @pagesize=10
  --返回第一頁的數(shù)據(jù)
  select top 10
   productid,
   productname,
   introduction  
   from product_test order by productid
 end

else if @curpage=-1

 select * from
  (select top 10 productid,
   productname,
   introduction

  from product_test order by productid desc ) as aa 
  order by productid
else

 begin
  if @isnext=1
   --翻到下一頁
   select top 10 productid,
   productname,
   introduction
  from product_test where productid > @lastid order by productid
  
  
  else
   --翻到上一頁
   select * from
    (select top 10 productid,
   productname,
   introduction
  from product_test where productid < @firstid  order by productid desc) as bb order by productid
 end
 

百萬數(shù)據(jù)翻頁就像100條數(shù)據(jù)一樣!

http://www.jyklzz.net/web/jyk/index.asp 這里有詳細(xì)的說明

 

 

菜鳥學(xué)堂:
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 什邡市| 东方市| 马龙县| 绩溪县| 定边县| 文山县| 大港区| 雅江县| 孝感市| 澄迈县| 河间市| 济宁市| 晋城| 肇源县| 连平县| 会宁县| 礼泉县| 元氏县| 海原县| 炉霍县| 通化县| 噶尔县| 泽库县| 县级市| 安乡县| 威海市| 青神县| 江陵县| 盐源县| 贵德县| 沙湾县| 长白| 乌拉特后旗| 惠东县| 政和县| 桦甸市| 西乌| 宁津县| 四会市| 铜川市| 三河市|