Home > Interview Questions > SQL Server > what is the use of @@TRANCOUNT function in SQL server?

what is the use of @@TRANCOUNT function in SQL server?

by Narain_Siddharth   on Jun 01, 2011   Category: SQL Server   |  Level: Intermediate   |  Views: 138    |  Points: 25     |  Silver 



The @@TRANCOUNT function in SQL server is used to returns no of active transactions in the current connection, and return type of this function is integer. when we use BEGIN TRANSACTION, it increments the @@TRANCOUNT and ROLLBACK TRANSACTION, COMMIT TRANSACTION will decrease @@TRANCOUNT count. see the below code.

BEGIN TRANSACTION
UPDATE employee SET salary = 1000000
WHERE emp_grade = '7'

IF @@ROWCOUNT > 0
COMMIT TRAN

IF @@TRANCOUNT > 0
BEGIN
ROLLBACK TRAN
END

Like this question? Bookmark and Share:


  « Previous Question  |  Next Question »

  User Responses | Post .Net Interview Question
No Response found!
Submit feedback about this Interview Question
Please sign in to post feedback