|||
merge into 解决用B表跟新A表数据,如果A表中没有,则把B表的数据插入A表;
语法:
MERGE INTO [your table-name] [rename your table here]
USING ( [write your query here] )[rename your query-sql and using just like a table]
ON ([conditional expression here] AND [...]...)
WHEN MATHED THEN [here you can execute some update sql or something else ]
WHEN NOT MATHED THEN [execute something else here ! ]
Merge Into emp_bak i
Using ( Select emp_no,Name,salary,bonus From emp) s
On (i.emp_no=s.emp_no)
When Matched Then
Update Set i.salary=s.salary,i.bonus=s.bonus
When Not Matched Then
Insert (i.emp_no,i.Name,i.salary,i.bonus) Values(s.emp_no,s.Name,s.salary,s.bonus);
如果数据量很大,此sql效率非常高
Powered by Discuz! X3.2
© 2001-2013 Comsenz Inc.