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!

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
14,163 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,666 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Erland Sommarskog 113.7K Reputation points MVP
    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.


  2. 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

Your answer

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