Search code examples
c#sqlsql-serverperformancesqlbulkcopy

Any way to SQLBulkCopy "insert or update if exists"?


I need to update a very large table periodically and SQLBulkCopy is perfect for that, only that I have a 2-columns index that prevents duplicates. Is there a way to use SQLBulkCopy as "insert or update if exists"?

If not, what is the most efficient way of doing so? Again, I am talking about a table with millions of records.

Thank you


Solution

  • I would bulk load data into a temporary staging table, then do an upsert into the final table. See here for an example of doing an upsert.