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 任务执行的图形,从中我们可以比较出一些性能上的差异

具体的一些显示的一些术语大家可以去网上搜索。

同时附上同库的任务截图

接上图

原文地址:https://www.cnblogs.com/rongfengliang/p/3723235.html