使用預存程序實現資料分頁

來源:互聯網
上載者:User
在.NET中雖然GridView,DataGrid,等控制項都提供了分頁功能,但當資料表中的資料容量過大時使用此種方式分頁顯然不適宜,過多的資料會使頁面變得十分龐大,導致效能的下降,為此我們可以使用預存程序在SQL Server資料庫中實現分頁,每次返回一定行數的資料,不至於影響到頁面因資料過大而變得龐大,實現思路如下

資料表裡面是否有主鍵和索引對效能的影響相當大
/*第一個參數是每頁條數,第二個參數是目標頁碼*/

CREATE proc sp_fixpage @pagesize int,@destpage int  as
set nocount on
declare @id int
declare @startid int  

select @startid = (@destpage - 1)*@pagesize

set rowcount @startid
select @id = id from t_member

set rowcount @pagesize
set nocount off
select * from t_member where id > @id order by id
GO

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.