Martin
Martin

Reputation: 755

sql transaction don't roll back

In transact-sql, what is the purpose of enclosing different actions between "begin transaction" and "commit transaction"

I noticed that when an exception is thrown in the middle of the function It Does not roll back the transaction. if an error occurs, How to roll back the transaction?

Upvotes: 2

Views: 1032

Answers (1)

Gulli Meel
Gulli Meel

Reputation: 891

Best way to have proper error handling using try and catch. Then do actions in catch clause based on the error like roll back tran or etc.

However, if you do not want to change the code at all.Specify following before your code execution.

set xact_abort on

This will cause auto rollback of transaction.But best soltuion will be to catch and handle errors properly.

Upvotes: 2

Related Questions