Thursday, March 29, 2012

Does SQL Server check for constraint violation when COMMIT is called?

If there are two different transactions, both of which update the username column to 'xyz' for userid = 234 in 'Users' table. This is a unique value for username. Ater this update each transaction adds a row to 'AppLog' table. The transaction is only committed after second operation.

The 'username' column has a unique constraint on it.

If transaction isolation level is 'read committed', and both transaction execute the first operation when neither of the transactions have been committed, then the transaction that calls COMMIT later will error out or not? If COMMIT does not check constraints then it will NOT error out. As a result we will have a violation of unique constraint happening without any error being thrown by SQL Server.

sun21170:

If COMMIT does not check constraints then it will NOT error out.

The statements that COMMIT causes to execute will be checked for contraint violations. If SQL Server allowed constraint violations, it wouldn't be around very long.

sql

No comments:

Post a Comment