SQL Flow Field Guide

@@TRANCOUNT

Catalog support for SQL Server 2022 (16.x) and 2025 (17.x)

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 Flow
BEGIN 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.