SqlBulkCopy with Duplicate recorde RRS feed

  • Question


    Hi there,


        I am trying to use SqlBulkCopy to move a big rows number from access DB to Sql server but there is a duplicate records in the sql server with the access DB. Is there is any way to ignore the duplicate recored while I am using Bulkcopy the data?


    Thank you in advance.



    Friday, October 26, 2007 5:06 PM

All replies

  • There are two options one create a unique index and use the IGNORE_DUP_KEY option which means only none duplicate part of the insert will succeed. The other is to make both tables UNION compatible and use UNION to move the data instead of BulkCopy, reason UNION performs implicit Distinct to remove duplicates. Hope this helps.



    Friday, October 26, 2007 6:30 PM
  • But I have primary key in the table is this will work if i add another uniq key to the table or the duplicate record should be identically match



    Thank you


    Friday, October 26, 2007 7:05 PM
  • You could use temp table or use unique constraint and create an non clustered index and use the IGNORE_DUP_KEY, you have to create the table before you use this option because SQL Server 2005 will not let you create unique constraint or index if duplicate is in the table.  The other option is UNION it removes duplicates but very slow.


    Friday, October 26, 2007 7:25 PM