SQL SERVER實現基本的分頁功能,sqlserver實現分頁

來源:互聯網
上載者:User

SQL SERVER實現基本的分頁功能,sqlserver實現分頁
SQL SERVER實現基本的分頁功能利用NOT IN 和 SELECT TOP來分頁

use WH_WorkshopInforSys--建立暫存資料表select IDENTITY(int,1,1) as id,* into mytablefrom dbo.PnlBaobiao-- 分頁查詢select top 10 *from mytablewhere id not in (select top 40 id from mytable order by id)order by id-- 刪除表drop table mytable


由於原來的表格中沒有對錶做一個序號,那麼所以我們要先建立一個暫存資料表儲存帶自增序號的表,然後對這個表進行分頁操作,最後再刪除掉暫存資料表,所以可能效率比較低,這這是思路最清晰的一種方法,而且對於本來就有ID的表來說,這查詢速度還是可以接受的。
,表格從41開始
怎實現高效的 jsp 分頁顯示功可以(資料庫是sqlserver),最好有執行個體;

用sql分頁。
select top 10 from tablename where id not in (select top 10 id from tablename)

一般的分頁是一次性把資料庫中資料全部取出來,在頁面進行分頁。
mssql 可以通過top關鍵字來實現查詢的時候就只查顯示的部分。
 
用sqlserver實現分頁的語句

給你一個參考
String sql ="select top 5 * from bean where id not in (select top "+5*(pageNum-1)+" id from bean order by id)";
 

相關文章

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.