Facebook Twitter Sign in | Join
Smartest Kid at School
Getting started with SSIS - Part 9: Debugging SSIS packages
First Time? You can support us by signing up. It takes only 5 seconds. Click here to sign up. If you already have an account, click here to login.
Pushing database changes needn't be hard work with SQL Compare
Sponsored [Advertise Here]
Syndicate your blog!
beyondrelational.com
Syndicate your blog with us to get wider reach into the technology community. Click here to get started.

SSRS Tutorial - Getting Started with SQL Server Reporting Services
beyondrelational.com
This tutorial will help you to get started with SQL Server Reporting Services (SSRS)

SQL Server Interview Questions and Answers
sqlauthority.com
This book will flow in a “Question & Answer” mode from start to finish to help you grasp concepts faster and get to the point quickly.
Loading

@@TRANCOUNT is always incremented in a trigger

The system variable @@TRANCOUNT is used to get the number of transactions that are active. Consider the following code

begin transaction
select 3
select @@TRANCOUNT 
commit transaction

The result of @@TRANCOUNT is 1. Consider the following code.

begin transaction
select 3
begin transaction
select 456
select @@TRANCOUNT 
commit transaction
commit transaction


The result of @@TRANCOUNT is 2.

So whenever there is a transaction the variable @@TRANCOUNT gets incrementedx by 1. In an Auto commit mode if you dont use a transaction, @@TRANCOUNT will never gets incremented. But this variable gets incremented always in a trigger.

This is what BOL specifies

@@TRANCOUNT is incremented by one when entering a trigger, even when in autocommit mode. (The system treats a trigger as an implied nested transaction.)

So you need to be aware of this and use @@TRANCOUNT effectively.


Madhivanan
3 · 30% · 5956
1
Liked
1
Comments



Submit

1   Comments   

Subscribe to Notifications
  • I had learnt this one the hard way, so thank-you for posting it, Madhivanan!

    commented on Jan 28 2012 4:49AM  .  Report Abuse This post is not formatted correctly
    Nakul Vachhrajani
    8 · 18% · 3521

Your Comment


Sign Up or Login to post a comment.

Copyright © Beyondrelational.com