SQL: Why didn't my SQL Server transaction roll back on a primary key violation?
There’s a question that I hear all the time in SQL Server forums:
Why didn’t the transaction roll back when a primary key violation occurred?
Take a look at the code in the main image above. Would you expect it to execute the second and third INSERTs if the first INSERT failed with a primary key violation? So many people would. If you’re one of them, read on.
By default, that’s not how SQL Server works.
2020-05-07
