Connecting Tech Pros Worldwide Forums | Help | Site Map

Best way to add to DB while checking for duplicates

keys4worship
Guest
 
Posts: n/a
#1: Jul 23 '05
Situation:
Day 1
Table contains 100 items of actions imported via FTP. One of the fields
in the table can be updated to reflect an assigned unit code.


Day 2
Actions that may be duplicates of the table from Day 1 (with the
exception of the updated assigned unit field) are imported for
inclusion in the Table from Day 1.

Question- What is the best way to insure that any new items are added
to the table and that no duplicates are added at the sametime?

Assistance would be appreciated.


Simon Hayes
Guest
 
Posts: n/a
#2: Jul 23 '05

re: Best way to add to DB while checking for duplicates


A common solution is to load your data into a staging table which has
the same structure as the destination table. You can then use a query
like this to import only new rows:

insert into
dbo.Destination (col1, col2, ...)
select
col1, col2, ...
from
dbo.Staging s
where not exists (
select *
from dbo.Destination d
where s.keycol = d.keycol)

Simon

Closed Thread