sql server merge into 與update 批量更新1 百萬測試數據的性能比較


1. 1百萬的測試數據的生成

 declare @index int;
  begin
  set @index=0;
  while @index<1000000
  begin
  insert into teptable values(@index,STR(@index)+'name',str(@index)+'appname');
  set @index=@index+1;
  end
  end

2. merge into   sql 更新語句

-- 同庫數據更新
merge into teptable1 as  t1
using teptable1 as  t2
on t1.id=t2.id
when matched then
update set t1.name=t2.appname
when not matched then
insert
values (t2.id,t2.name,t2.appname);

-- 跨庫數據更新

merge into buckinsert.dbo.teptable1 as  t1
using userinfo.dbo.teptable as  t2
on t1.id=t2.id
when matched then
update set t1.appname=t2.appname+'demo aaa'
when not matched then
insert
values (t2.id,t2.name,t2.appname);

以上sql 分為跨庫與同庫之分

3. update  批量語句 sql

update  a set name = b.appname+'ssss' from teptable1 a,teptable1 b
where a.id =b.id

4. 生成的執行任務的截圖

a. 使用update 的任務截圖

b. merge into 的任務截圖 跨庫

 

5. 以上為測試以及sql 任務執行的圖形,從中我們可以比較出一些性能上的差異

具體的一些顯示的一些術語大家可以去網上搜索。

同時附上同庫的任務截圖

 

接上圖

 

 

 

 

 

 

 

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM