Thursday, March 29, 2012

Error: duplicate key row

What might cause the following error when inserting rows in tables that have primary keys defined as IDENTITY (1,1)?

duplicate key row in object 'aa' with unique index 'aa'

I have seen this happen frequently when data has been bulk loaded sometime in the past into a table that has an IDENTITY key. This is especially common when you have a test environment in which some production data was bulk loaded to give some "good test data." To me it means that an identity number has "already been used" as a record key.


Dave

|||The rows are inserted one at a time using the parent IDENTITY key as a FK constraint in the child table which also has an IDENTITY KEY. However, this scenario does not sound like it would cause an error.|||

Can you post the table structures? That would help us to see what your problem might be.

If you can post a few statements that cause the duplicates, that would even be better.

|||

If you have the property NOT FOR REPLICATION enabled for the identity column.

Merging changes would allow the exact id values to be inserted rather than a new value that would give the error if same id value exists in the participating server.

similarly, if you are trying to insert manually using SET IDENTITY_INSERT table ON...

No comments:

Post a Comment