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 01/06/2011   Category: SQL Server   |  Level: Intermediate   |  Views: 2411    |  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



« What is the use of REVERSE() function in SQL server?
» what is the use of @@ROWCOUNT function in SQL server?
Post Question  |  Question Home

Recent Posts

User Responses


No response found, be the first to review this question.

Submit feedback about this code snippet

Please sign in to post feedback

Latest Posts