@@TRANCOUNT function returns the number of active transactions for the current connection.
The BEGIN TRANSACTION statement increments @@TRANCOUNT by 1. ROLLBACK TRANSACTION decrements @@TRANCOUNT to 0, except for ROLLBACK TRANSACTION savepoint_name, which does not affect @@TRANCOUNT. COMMIT TRANSACTION or COMMIT WORK decrement @@TRANCOUNT by 1.
Syntax of @@TRANCOUNT Function :
@@TRANCOUNT
Return type of @@TRANCOUNT function is an integer.
Examples of @@TRANCOUNT Function :
Example 1 : Use of @@TRANCOUNT function in select clause
Output
0
Above example returns 0 means currently there is no active transaction for the current connection.