1 merge into emp_commission ec 2 using (select * from emp) emp 3 on (ec.empno=emp.empno) 4 when matched then 5 update set ec.comm = 1000 6 delete where (sal < 2000) 7 when not matched then 8 insert (ec.empno,ec.ename,ec.deptno,ec.comm) 9 values (emp.empno,emp.ename,emp.deptno,emp.comm)
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/23895263/viewspace-681081/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/23895263/viewspace-681081/
本文介绍了一种使用SQL的MERGE语句来同步两个表数据的方法。具体操作包括根据匹配条件更新目标表中的记录,插入新记录,并有条件地删除记录。此过程通过一个具体的例子展示,该例子涉及到了数据的更新、插入和删除操作。
3万+

被折叠的 条评论
为什么被折叠?



