Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Differences in large amounts of data
Message
From
08/12/2006 22:30:41
Mike Yearwood
Toronto, Ontario, Canada
 
 
To
08/12/2006 19:17:38
General information
Forum:
Microsoft SQL Server
Category:
Database management
Environment versions
SQL Server:
SQL Server 2000
Miscellaneous
Thread ID:
01176309
Message ID:
01176335
Views:
8
>Given a large database, and a complete new set of data that may have many duplicates with the existing set of data, what would be the most efficient way to find the differences (items no loger there, items new, and items modified)??

Well, I've had good results with using 2 sql commands provided there is a common ID between the two files.

select * from table1 tgt ;
inner join table2 src on tgt.id = src.id ;
where ;
src.field1 # tgt.field1 ;
or src.field2 # tgt.field2 ;
into cursor c_Modifications

Repeat as many fields as you have. I think the first field that is different stops the processing of the remaining OR conditions.

select * from table2 src ;
where src.id not in (select id from table1) ;
into cursor c_Additions

A third query could give the records that are no longer in the new set of data.

select * from table1 src ;
where src.id not in (select id from table2) ;
into cursor c_Removed

HTH
Previous
Reply
Map
View

Click here to load this message in the networking platform