SQL Server Output Rollback Processing

In my reading, I saw two methods for processing transaction rollbacks in the CATCH section of a SQL Server stored procedure:

1: if @@trancount > 0 ROLLBACK
2: if XACT_STATE() <> 0 ROLLBACK TRAN

Which is better and why?

+3
source share
1 answer

This MSDN articl e is a good link. Quote:

Both the XACT_STATE and @@ TRANCOUNT functions can be used to detect whether the current request has an active user transaction. @@ TRANCOUNT cannot be used to determine if this transaction was classified as an inconvenient transaction. XACT_STATE cannot be used to determine if there are nested transactions.

, , COMMIT , XACT_STATE , , , @@TRANCOUNT . ROLLBACK, , , .

+6

Source: https://habr.com/ru/post/1779370/


All Articles