@@TRANCOUNT(Transact-SQL)

적용 대상: Microsoft Fabric의 SQL ServerAzure SQL DatabaseAzure SQL Managed InstanceAzure Synapse Analytics AnalyticsPlatform System(PDW) Warehouse

현재 연결에서 발생한 BEGIN TRANSACTION 문의 수를 반환합니다.

Transact-SQL 구문 표기 규칙

Syntax

@@TRANCOUNT  

참고

이 구문은 Azure Synapse Analytics의 서버리스 SQL 풀에서 지원되지 않습니다.

참고 항목

SQL Server 2014(12.x) 및 이전 버전에 대한 Transact-SQL 구문을 보려면 이전 버전 설명서를 참조 하세요.

반환 형식

integer

설명

BEGIN TRANSACTION 문은 @@TRANCOUNT를 1씩 늘립니다. @@TRANCOUNT에 영향을 주지 않는 ROLLBACK TRANSACTION savepoint_name을 제외한 ROLLBACK TRANSACTION은 @@TRANCOUNT를 0으로 줄입니다. COMMIT TRANSACTION 또는 COMMIT WORK는 @@TRANCOUNT를 1씩 줄입니다.

예제

A. BEGIN 및 COMMIT 문의 영향

다음 예에서는 중첩된 BEGINCOMMIT 문이 @@TRANCOUNT 변수에 주는 영향을 보여 줍니다.

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

B. BEGIN 및 ROLLBACK 문의 영향

다음 예에서는 중첩된 BEGIN TRANROLLBACK 문이 @@TRANCOUNT 변수에 주는 영향을 보여 줍니다.

PRINT @@TRANCOUNT  
--  The BEGIN TRAN statement will increment the  
--  transaction count by 1.  
BEGIN TRAN  
    PRINT @@TRANCOUNT  
    BEGIN TRAN  
        PRINT @@TRANCOUNT  
--  The ROLLBACK statement will clear the @@TRANCOUNT variable  
--  to 0 because all active transactions will be rolled back.  
ROLLBACK  
PRINT @@TRANCOUNT  
--Results  
--0  
--1  
--2  
--0  

참고 항목

BEGIN TRANSACTION(Transact-SQL)
COMMIT TRANSACTION(Transact-SQL)
ROLLBACK TRANSACTION(Transact-SQL)
시스템 함수(Transact-SQL)