Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

bulk insert 1

Status
Not open for further replies.

rajkum

Programmer
Jul 30, 2003
48
US
Hi,

I have a requirement where I have to load a set of data from datawarehouse into a database server.
How do i ensure the next time i update that i am inserting only new records.

Thanks,
Raj
 
INSERT INTO DestinationTable
SELECT ColumnList
FROM IncomingData inc
WHERE NOT EXISTS
(
SELECT dt.PrimaryKeyColumn
FROM DestinationTable dt
WHERE inc.PrimaryKeyColumn = dt.PrimaryKeyColumn
)


--Angel [rainbow]
-----------------------------------
Every time I lose my mind, I wonder
if it's really worth finding.
 
You are better off having some value that you can check on the table to make sure that you only extract updated records since the last import.
Import these into a staging table then update recs on the primary key and insert new ones (or just delete ones that exist and insert everything).

======================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top