Global variable @ @TRANCOUNT:
Returns the number of active transactions for the current connection.
An explicit transaction:
Begin TRANSACTION The beginning of a clear real transaction.
The most common type of transaction.
Implicit transactions:
By setting the Setimplicit_transactions on statement,
Sets the stealth transaction mode to open.
The subsequent T-SQL statement automatically starts a new transaction.
Commits or rolls back a transaction, and the next T-SQL statement starts a new transaction.
Commit transactions automatically:
The default mode for SQL Sever.
Each individual T-SQL statement is a transaction.
--commit effect on transaction number (nested transactions used) print @ @TRANCOUNT--look at the number of transactions without a transaction begin tran--start transaction PRINT @@ trancount--start Transaction, @ @TRANCOUNT will be set to 1 begin tran--start transaction PRINT @ @TRANCOUNT--Number of transactions plus 1 COMMIT tran--Commit Second transaction print @ @TRANCOUNT--Number of transactions minus 1 commit TRAN--commit first transaction, number of transactions minus 1 PRINT @ @TRANCOUNT GO
Operation Result:
9-04 nested transactions and transaction classifications (1)