sqlserver merge into

create table #ttt(id int,name nvarchar(10));
merge into #ttt t
using (select 1 as id ,'eee' as name ) b
on (t.id = b.id)
when matched then
update set t.name = b.name
when not matched then
insert(id,name) values(b.id,b.name);



select * from #ttt;




merge into  a
using  b
on (a.id = b.id)
when matched then
update set a.name = b.name
when not matched then
insert(id,name) values(b.id,b.name);


select * from a;
原文地址:https://www.cnblogs.com/tiancai/p/5070109.html