How can I use SqlBulkCopy to avoid inserting duplicates?

c# sqlbulkcopy sql-server-2008

Question

I am going to use SqlBulkCopy, but I need to prevent duplicates insert. What is the best way to do it? Have I do check existence for each item before make execute WriteToServer command?

1
0
3/29/2012 10:17:11 AM

Popular Answer

The best way to do this would be to add a unique index onto the table you are inserting the data into. This will prevent any duplicate entries from being added to the table.

This also prevents you from having to potentially load too much data into memory and creating other problems for yourself.

1
8/11/2016 3:59:35 PM


Related Questions





Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow