Share via

Change Tracking causes errors to appear 'Cannot insert duplicate key row in object'

Robert 1 Reputation point
2021-08-03T11:02:06.49+00:00

Hi,

I am using SQL 2019 Enterprise Version. I have a simple process that runs with no errors updating / merging between tables in the same database. If i enable change tracking on one of the destination tables the process starts to fail with the error Cannot insert duplicate key row in object ' XXXXX ' with unique index '. As soon as i disable the change tracking everything works fine again. There are no errors in the log.

Anyone else experienced this issue, or know how to resolve the problem?

Thank you!

Developer technologies | Transact-SQL
Developer technologies | Transact-SQL

A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.

SQL Server | Other
{count} votes

2 answers

Sort by: Most helpful
  1. Robert 1 Reputation point
    2021-09-09T07:54:21.96+00:00

    Just to add an update, we removed all the merge statements and are just using updates and inserts, and still seeing the same message. We also upgraded to the latest cu12 and still seeing the same issue.

    I'm reaching out to Ms today hopefully to get some assistance on it.

    0 comments No comments

  2. Erland Sommarskog 133.1K Reputation points MVP Volunteer Moderator
    2021-08-04T10:11:18.63+00:00

    It certainly sounds like a bug in the product.

    I'm afraid that we cannot do much here. Well, we could ask you to post a repro that demonstrates the issue, but that could take you a bit of time. And in the end we might only say "yes, we can repro this", but unless there is something that stands out as special, I don't think that we will be able to help you to get around the problem.

    So I would advice you that you first check "SELECT @@version" and verify that you are on CU11 of SQL 2019. If you are not, apply CU11, which is the most recent CU for SQL 2019, to see if that it helps.

    If it does not, open a support case, if this is a blocking issue for you. (And I guess it is.)

    Well, an alternative is of course to replace the MERGE with individual INSERT and UPDATE statements, and there are blog posts out there that gives MERGE bad press. But I find MERGE quite nifty myself, so I am not keen on that workaround.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.