sql merge的用法实例(学习日记)

来源:互联网 发布:外部端口80被占用 编辑:程序博客网 时间:2024/06/06 07:27

merge我理解的意思就是根据on的判断来执行Insert还是update

 

 

merge into mytable as my ----mytable主表
using cy_contract as cy  ---cy_contract 引用的表
on my.id = cy.ctid  ----两张表的关系或者条件
when matched then  ----如果满足
update set name = cy.ctname  ----- 执行update
when not matched then  ---否则
insert (name) values (cy.ctname); ------执行insert