Copy missing rows from one table to another in sql server with stored procedure

我是研究僧i 提交于 2019-12-10 10:49:34

问题


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

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