USE AdventureWorks; GO BEGIN TRANSACTION; GO DELETE FROM HumanResources.JobCandidate WHERE JobCandidateID = 10; DELETE FROM HumanResources.JobCandidate WHERE JobCandidateID = 11; DELETE FROM HumanResources.JobCandidate WHERE JobCandidateID = 12; GO COMMIT TRANSACTION; GO
What happens if the first delete instruction fails? Will the 2nd and 3rd delete operations be performed? There is no error handling in the example, will it leave an open transaction in case of an exception, or will SQL Server refuse the transaction automatically? Open transaction = locked resources, right?
I decide if I should apply TRY ... CATCH to stored procedures that use transactions.
I know about set xact_abort on
, but I want to know what happens without it.
Here is what I found in the documents - Transaction Management (Database Engine):
If the error prevents the transaction from completing successfully, SQL Server automatically rolls back the transaction and frees all resources held by the transaction
However, I read in other posts that automatic rollback does not start.
source share