sqlserver百萬級資料高效能分頁
阿新 • • 發佈:2018-11-27
批量插入100萬條資料 用於測試
原文地址:https://www.cnblogs.com/celine/p/9101871.html
/*建立表*/
create table tb(
km_h int,
zkzh int,
ss_h int,
zw_h int
)
//科目號|考生編號|室試號|座位號
//1 158994 590 94
drop table tb; //刪除表資料和表結構
delete from tb; //刪除表資料,保留表結構
select * from tb; //查詢表資料
/*使用sql server插入100萬資料*/
declare @zkzh int,
@ss_h int,
@zw_h int;
set @zkzh=100001;
while @zkzh<=1100000
begin
set @ss_h=1;
while @ss_h<=10000
begin
set @zw_h=1;
while @zw_h<=100
begin
insert into bigdata.dbo.tb(km_h,zkzh,ss_h,zw_h) values(1,@zkzh,@ss_h,@zw_h);
set @ [email protected]_h+1;
set @[email protected]+1;
end;
set @[email protected]_h+1;
end;
end;
下面是分頁查詢程式碼:
這裡只記錄了效能最好的一種:原文地址:https://www.cnblogs.com/xiaoMzjm/p/3933077.html
select * from ( select *,row_number() over(order by zkzh desc)n from tb )hhh where hhh.n>50000 and hhh.n<=50010