sql server merge into 与update 批量更新

2021/8/23

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);