问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/11481345/sql-transaction-dont-roll-back