SQL: compare two table record by record

 ̄綄美尐妖づ 提交于 2019-12-01 14:32:36
alex

If tables have same column definition, the fastes way is just use 'except' clause:

SELECT * from Table1
except
SELECT * from Table2

also run it in opposite way:

SELECT * from Table2
except
SELECT * from Table1

You'll see the exact set difference:

EXCEPT and INTERSECT

E.J. Brennan

Redgate has a great tool for this, if you'd rather just spend a few dollars:

You can get a free trial to see if it suits your needs.

Can't you just...

SELECT * FROM Table1 LEFT JOIN Table2 ON <your matching criteria>

...and then perform INSERT for the rows whose right "half" is NULL and UPDATE for those whose isn't?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!