在程序的開發(fā)過程中,處理分頁是大家接觸比較頻繁的事件,因為現(xiàn)在軟件基本上都是與數(shù)據(jù)庫進行掛釣的。但效率又是我們所追求的,如果是像原來那樣把所有滿足條件的記錄全部都選擇出來,再去進行分頁處理,那么就會多多的浪費掉許多的系統(tǒng)處理時間。為了能夠把效率提高,所以現(xiàn)在我們就只選擇我們需要的數(shù)據(jù),減少數(shù)據(jù)庫的處理時間,以下就是常用SQL分頁處理:
1、SQL Server、Access數(shù)據(jù)庫
這都微軟的數(shù)據(jù)庫,都是一家人,基本的操作都是差不多,常采用如下分頁語句:
PAGESIZE:每頁顯示的記錄數(shù)
CURRENTPAGE:當前頁號
數(shù)據(jù)表的名字是:components
索引主鍵字是:id
以下是引用片段:
select top PAGESIZE * from components where id not in
(select top (PAGESIZE*(CURRENTPAGE-1))
id from components order by id)order by id
如下列:
以下是引用片段:
select top 10 * from components where id not in
(select top 10*10 id from components order by id)
order by id
從101條記錄開始選擇,只選擇前面的10條記錄
1、SQL Server、Access數(shù)據(jù)庫
這都微軟的數(shù)據(jù)庫,都是一家人,基本的操作都是差不多,常采用如下分頁語句:
PAGESIZE:每頁顯示的記錄數(shù)
CURRENTPAGE:當前頁號
數(shù)據(jù)表的名字是:components
索引主鍵字是:id
以下是引用片段:
select top PAGESIZE * from components where id not in
(select top (PAGESIZE*(CURRENTPAGE-1))
id from components order by id)order by id
如下列:
以下是引用片段:
select top 10 * from components where id not in
(select top 10*10 id from components order by id)
order by id
從101條記錄開始選擇,只選擇前面的10條記錄