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

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

同时附上同库的任务截图

 

接上图

 

 

 

 

 

 

 

 

 

 

 

posted on   荣锋亮  阅读(6964)  评论(0编辑  收藏  举报

编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示