高效批量插入資料,提高工效

2021-09-24 17:52:35 字數 1958 閱讀 1209

/*

批量插入錶值,sql方法

本方是從table02裡取值,並且這些值在table01表不存在,把這些不存在的值直接插入table01的樣例

以博高手一笑。

*/create table table01

(f1 varchar(255) default '',

f2 varchar(255) default '',

f3 varchar(255) default '',

f4 varchar(255) default '')go

create unique index unique_index01 on table01 (f1,f2)

gocreate table table02

(f1 varchar(255) default '',

f2 varchar(255) default '',

f3 varchar(255) default '',

f4 varchar(255) default '')go

create unique index unique_index01 on table02 (f1,f2)

go--插入樣例資料

declare @i int

insert table01(f1,f2,f3,f4)    values('1','','','')

insert table01(f1,f2,f3,f4)    values('2','','','')

insert table01(f1,f2,f3,f4)    values('3','','','')

insert table02(f1,f2,f3,f4)    values('1','','','')

insert table02(f1,f2,f3,f4)    values('2','','','')

insert table02(f1,f2,f3,f4)    values('3','','','')

insert table02(f1,f2,f3,f4)    values('4','','','')

insert table02(f1,f2,f3,f4)    values('5','','','')

insert table02(f1,f2,f3,f4)    values('6','','','')

go--左聯接意思是僅顯示table02表裡與table01表裡相等的值。

--如果在table01表裡沒有,則f5,f6,f7,f8 為 null

select table02.f1 ,table02.f2,table02.f3,table02.f4,

table01.f1 as f5 ,table01.f2 as f6,table01.f3 as f7,table01.f4 as f8

from table02 

left join table01 on table02.f1 = table01.f1 and table02.f2 = table01.f2 

go/*把結果插入table01*/

insert table01

(f1,f2,f3,f4)

select tx.f1,tx.f2,tx.f3,tx.f4

from 

(select table02.f1 ,table02.f2,table02.f3,table02.f4,

table01.f1 as f5 ,table01.f2 as f6,table01.f3 as f7,table01.f4 as f8

from table02 

left join table01 on table02.f1 = table01.f1 and table02.f2 = table01.f2 

) tx

where tx.f5 is null

goselect * from table01

godrop table table01 

drop table table02 

高效率批量插入上億資料

轉至 create table create table tmp test chas lee f01 varchar2 20 f02 number 10 not null,f03 varchar2 21 f04 varchar2 21 f05 number,f06 number 20 建立乙個臨時表...

批量插入資料

drop procedure if exists pre 如果存在先刪除 delimiter 以delimiter來標記用 表示儲存過程結束 create procedure pre 建立pre 儲存方法 begin declare i int default 12 declare n int de...

用CPS(冠軍高效系統)提高工作效率

工作效率低最主要的原因是缺乏時間管理或者時間管理混亂,利用好的工具可以大大提高時間管理技能,提公升工作效率。在這裡推薦一下冠軍高效系統。冠軍高效系統cps champion productivity system 能夠幫助掌控每天所有的大小事項,是提高工作效率與產出的高效工作流程系統。這套系統的 以...