Search This Blog

Monday, February 25, 2013

@@TRANCOUNT (SQL Server)

SQL Server > Built-In Functions > @@TRANCOUNT

Returns the number of BEGIN TRANSACTION statements that have occurred on the current connection.

Example:


PRINT @@TRANCOUNT
BEGIN TRAN --  The BEGIN TRAN statement will increment the  transaction count by 1.
PRINT @@TRANCOUNT
COMMIT     --  The COMMIT statement will decrement the  transaction count by 1.
PRINT @@TRANCOUNT

Result:
0
1
0