问题
I have to tables in different databases (on the same server) that are identical. I need to transfer the data rows from the left database table to the right database table, but I only want to transfer the rows that aren't in the right database table already.
Is there a neat way of doing this?
Im using SQL Server 2008 R2
回答1:
Assuming that you can uniquelly identify a row with column id:
insert into databasename..tablename
select * from datababasename2..tablename2
where id not in (select id from databasename..tablename)
来源:https://stackoverflow.com/questions/10885129/copy-missing-rows-from-one-table-to-another-in-sql-server-with-stored-procedure