copying differential data | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

copying differential data

I have 2 tables. Table A and Table B. Both the tables are in different databases and have the same structure. The primary key is a combination of 3 attributes. Table A is the master table. I want to copy only the differential data from table A to table B (i.e., only those records that are not available in Table B must be copied from Table A). How can this be done keeping in mind especially since the primary key is a combination of 3 attributes. I am using SQL Server 2005.
Thanks, StarWarsBigBang
do a comparision of 3 columns in the where clause in same order as its defined in primay key order.
insert into tableb
select a.* from tablea a
where not exists (select 1 from tableb b on a.col1 = b.col1 and a.col2 = b.col2 and a.col3 = b.col3)
MohammedU.
Moderator
SQL-Server-Performance.com All postings are provided “AS IS” with no warranties for accuracy.

Thanks MohammedU & Viksar. I am getting the error ‘Incorrect syntax near the keyword ‘ON’. Where exactly is the problem? Thanks, StarWarsBigBang
Thanks MohammedU & Viksar. I am getting the error ‘Incorrect syntax near the keyword ‘ON’. Where exactly is the problem? Thanks, StarWarsBigBang
My bad…change ON to WHERE insert into tableb
select a.* from tablea a
where not exists (select 1 from tableb b where a.col1 = b.col1 and a.col2 = b.col2 and a.col3 = b.col3)
MohammedU.
Moderator
SQL-Server-Performance.com All postings are provided “AS IS” with no warranties for accuracy.

]]>