乙個高效的資料分頁的儲存過程 可以輕鬆應付百萬資料

2021-04-14 01:47:34 字數 1246 閱讀 8318

程式**

create procedure pagetest  --用於翻頁的測試

--需要把排序字段放在第一列 (

@firstid nvarchar(20)=null,  --當前頁面裡的第一條記錄的排序欄位的值

@lastid nvarchar(20)=null,  --當前頁面裡的最後一條記錄的排序欄位的值

@allcount int output,   --返回總記錄數

@pagesize int output,   --返回一頁的記錄數

@curpage int     --頁號(第幾頁)0:第一頁;-1最後一頁。 )

asif @curpage=0

begin

--統計總記錄數

select @allcount=count(productid) from product_test

set @pagesize=10

--返回第一頁的資料

select top 10

productid,

productname,

introduction  

from product_test order by productid

endelse 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據稱 百萬資料翻頁就像100條資料一樣!

乙個高效的資料分頁的儲存過程

create procedure pagetest 用於翻頁的測試 需要把排序字段放在第一列 asif curpage 0 begin 統計總記錄數 select allcount count productid from product test set pagesize 10 返回第一頁的資料 ...

乙個高效的資料分頁的儲存過程

高效的資料分頁的儲存過程 create procedure pagetest 用於翻頁的測試 需要把排序字段放在第一列 asif curpage 0 begin 統計總記錄數 select allcount count productid from product test set pagesize...

乙個高效的分頁儲存過程

最近在做乙個幾百萬條資料的分頁查詢,研究了各種方案,在本機上用專案的實際資料庫做測試,測試過程 is very 痛苦,不堪回首ing。現在廢話不多說,直接上結果,相信這也是大多數搜尋答案的人最願意看的方式。以下是儲存過程的 1 create procedure dbo p gridviewpager...