最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

MySQL提高分頁效率

 更新時(shí)間:2015年10月02日 10:23:11   投稿:lijiao  
本文分享的這段代碼是大數(shù)據(jù)量時(shí)提高分頁的效率的測試代碼,感興趣的小伙伴可以參考一下

下面就是大數(shù)據(jù)量時(shí)提高分頁的效率的測試代碼,分享給大家。

--提高分頁效率:實(shí)現(xiàn)分頁時(shí)只讀取顯示數(shù)據(jù),需要先在數(shù)據(jù)庫創(chuàng)建數(shù)據(jù)庫“TestForPaging”
use TestForPaging
go
--創(chuàng)建表SomeData
create table SomeData
(
id int primary key,
name varchar(30) null,
description text
)
go
--插入數(shù)據(jù)
insert into SomeData values(1,'num1','第1條')
go
insert into SomeData values(2,'num2','第2條')
go
insert into SomeData values(3,'num3','第3條')
go
insert into SomeData values(4,'num4','第4條')
go
insert into SomeData values(5,'num5','第5條')
go
--數(shù)據(jù)條目總數(shù)
select count(*) from SomeData
go
--給每條記錄添加一個(gè)數(shù)據(jù)級別
select name,description,ROW_NUMBER() over(order by id desc)as dataLevel from SomeData
go
--查看指定的數(shù)據(jù)級別間的數(shù)據(jù)條目
select dataLevel,name,description from
(select name,description,row_number() over(order by id desc)as dataLevel from SomeData)
 as datawithleverl where dataLevel between 2 and 4
go
--實(shí)現(xiàn)查看指定的數(shù)據(jù)級別間的數(shù)據(jù)條目的存儲過程
create procedure GetDataPaged
(
@startRowIndex int,
@maximumRows int,
@sort varchar
)
AS
--確保指定sort
if len(@sort)=0
set @sort='id'
--帶參數(shù)的查詢
select dataLevel,name,description from
(select name,description,row_number() over(order by @sort desc)as dataLevel from SomeData) AS datawithleverl
WHERE dataLevel > (@startRowIndex*10) AND dataLevel <= (@startRowIndex*10 + @maximumRows)
go

以上就是本文的的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助。

相關(guān)文章

最新評論

黔西| 岳阳县| 谷城县| 科尔| 绍兴市| 太和县| 闽清县| 土默特右旗| 西华县| 松溪县| 上栗县| 宜兴市| 广德县| 葫芦岛市| 来凤县| 昌图县| 皮山县| 天门市| 安远县| 和田市| 桂阳县| 桦甸市| 罗江县| 德州市| 绥中县| 石泉县| 孝感市| 昌都县| 调兵山市| 岳阳县| 镇宁| 定远县| 连州市| 扶风县| 巨鹿县| 东山县| 古丈县| 南木林县| 南靖县| 公安县| 察哈|