Articles → SQL SERVER → @@TransactionCount in SQL server

@@TransactionCount in SQL server






Purpose





Impact of commit and rollback on @@TransactionCount





Example


PRINT @@TRANCOUNT  -- Count  = 1
BEGIN TRAN  -- Set @@TransactionCount = 2
    PRINT @@TRANCOUNT  
    BEGIN TRAN -- Set @@TransactionCount = 3 
		Rollback -- Resets @@TransactionCount to zero
        PRINT @@TRANCOUNT  
    BEGIN TRAN  -- Set @@TransactionCount = 1 
	BEGIN TRAN   -- Set @@TransactionCount = 2
	COMMIT  -- Reduces @@TransactionCount  to 1
    PRINT @@TRANCOUNT  
BEGIN TRAN -- Set @@TransactionCount = 2
COMMIT  -- Reduces @@TransactionCount  to 1
PRINT @@TRANCOUNT  



Output



Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Thursday, October 05, 2017

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250