Ignoring DupeKey Errors on Bulk Insert

  • Hello Volks,

    This may be a silly question and I'm probably showing my laziness, but I remember in MS Access that you could set the macro warnings to off and run an INSERT / SELECT From query and not have the transaction abort with DupeKey errors. Granted, in SQL I can write a transaction with a While Loop and do single SELECTs and INSERTs and check the @@ERROR if it's <> 0, but I was hoping I didn't have to. Does anyone know a way where I can do the bulk insert that will ignore the DupeKey erros?

    Thanks

  • You should drop and then re create the pkeys..or you can bulk insert into a temp table, and then insert from that table with a left join?

  • I don't see the need to recreate the keys. The idea here is to insert a sorted record set where the highest value of a certain field gets inserted first for the primary key. The rest are ignored. Then I have a unique set of all my highest values.

  • According to BOL, if you include the IGNORE_DUP_KEY option on a CREATE UNIQUE INDEX statement (clustered or nonclustered), you will get a warning for duplicate key values but the non-duplicate rows will still be inserted. Without this option (as you know) you get an error and all inserts are rolled back.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply