Checking the transaction state with @@transtate

@@transtate contains the current state of a transaction after a statement executes in the current user session. Unlike @@error, @@transtate is not cleared for each batch. @@transtate may contain the values in Table 15-3:

Table 15-3: @@transtate values

Value

Meaning

0

Transaction in progress: an explicit or implicit transaction is in effect; the previous statement executed successfully.

1

Transaction succeeded: the transaction completed and committed its changes.

2

Statement aborted: the previous statement was aborted; no effect on the transaction.

3

Transaction aborted: the transaction aborted and rolled back any changes.

@@transtate changes only due to execution errors. Syntax and compile errors do not affect the value of @@transtate. See “Checking the state of transactions” for examples showing @@transtate in transactions.