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.
INSERT INTO DestinationTable
SELECT ColumnList
FROM IncomingData inc
WHERE NOT EXISTS
(
SELECT dt.PrimaryKeyColumn
FROM DestinationTable dt
WHERE inc.PrimaryKeyColumn = dt.PrimaryKeyColumn
)
--Angel
-----------------------------------
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.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.