merge into 常用于联表更新

格式:

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

merge into ...

using (...)

on (...)

when matched then ...

when not matched then...

例如:A和B 匹配时更新,不匹配则插入

merge into A a

using (select * from B) b

on (a.id=b.id)

when matched then 

update set a.name=b.name

when not matched then

insert (id,name)=(b.id,b.name)

注意:update 后没有表名

Insert 后没有into 表名

 

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄