@@TRANCOUNT
reads transaction state
What changes
- Input
- transaction nesting count
- Output or change
- int
- Return type
- integer
Syntax at a glance
@@TRANCOUNT
Work example
Check the current transaction nesting counter before returning from a procedure.
Read state in the intended scope and immediately after the statement it describes. Treat host values as untrusted.
Check your work The three reads show two, one, and zero open transactions in that order.
Practice SQL
Open in SQL FlowBEGIN TRANSACTION;
BEGIN TRANSACTION;
SELECT @@TRANCOUNT AS OpenCount;
COMMIT TRANSACTION;
SELECT @@TRANCOUNT AS OpenCount;
ROLLBACK TRANSACTION;
SELECT @@TRANCOUNT AS OpenCount;
Open Microsoft Learn for full syntax, permissions, and details for your version.