Hi,I have a little bit of a dilema. I'm sure there is a solution, but I'm just not seeing it. I have two databases with the exact same table. I need to transfer the data from the first database to the second. Unfortunately, there are some common records shared between the two tables. I want to only insert those records that are missing. To help illustrate the issue, I created the below script (this is data between different tables but it is the same concept). I want to insert records id1=1,id2=2 and id1=2,id2=1. Since it is a compound key, I can't just do a NOT IN (...). I need to treat the two id fields together. CREATE TABLE [dbo].[Table1] ( [id1] [int] NOT NULL , [id2] [int] NOT NULL) ON [PRIMARY]GOCREATE TABLE [dbo].[Table2] ( [id1] [int] NOT NULL , [id2] [int] NOT NULL) ON [PRIMARY]GOALTER TABLE [dbo].[Table1] ADD CONSTRAINT [PK_Table1] PRIMARY KEY CLUSTERED ( [id1], [id2] ) ON [PRIMARY] GOALTER TABLE [dbo].[Table2] ADD CONSTRAINT [PK_Table2] PRIMARY KEY CLUSTERED ( [id1], [id2] ) ON [PRIMARY] GOINSERT INTO Table1 SELECT 1,1INSERT INTO Table1 SELECT 1,2INSERT INTO Table1 SELECT 2,1INSERT INTO Table1 SELECT 2,2INSERT INTO Table2 SELECT 1,1INSERT INTO Table2 SELECT 2,2INSERT INTO Table2 SELECT 3,1-- this doesn't work, I don't see how to query the records -- from table1 that DO NOT exist in table2insert into table2select * from table1where (id1 NOT IN (select id1 from table2) AND id2 NOT IN (select id2 from table2))
Nic