SqlShare.com Logo
 
Skip Navigation Links
Home
Video List
Events
Classes
About Us
Login / Register
Subscribe RSS Feed 

Confio Ignite

Using @@Trancount in Transactions

Did you know that it's possible to call COMMIT too many times, or not enough times when you're ending a transaction? @@Trancount lets you know what to do. Easy to use, and a great way to avoid ugly errors!

Duration:
2 mins 54 secs
Skill Level:
100
Rating:
4.43 out of 5
Publish Date:
January 17, 2010
Using @@Trancount in Transactions You must be logged in to view this video.  
Bookmark and Share
 
1=Poor, 3=Good, 5=Excellent

About the Author

Image of Andy Warren
Andy Warren is a software trainer focusing on SQL Server, a member of the PASS Board of Directors, and a principal in this site - SQLShare.com.

References

There are no downloads or recommended reading links for this video

Comments
dan provan on 1/18/2010
nice and simple...

John on 1/18/2010
I learn so much from you guys all the time - and I've been using SQL Server since version 7.

Steve Harris on 1/18/2010
what happens if you name your transaction block ... can you choose which block to commit?

Nasar Azam on 1/18/2010
Rollback decrement the @@Trancount to zero regardless of of the @@Trancount count. This is somewhat strange as I would expect the Rollback to decrement the Trancount by one. I am sure you are covering this in your future videos

John O'Sullivan on 1/18/2010
excellent video

Robert Fidelman on 1/18/2010
Good introduction!

Vic on 1/18/2010
From Books online: Committing inner transactions is ignored by the SQL Server Database Engine. The transaction is either committed or rolled back based on the action taken at the end of the outermost transaction. If the outer transaction is committed, the inner nested transactions are also committed. If the outer transaction is rolled back, then all inner transactions are also rolled back, regardless of whether or not the inner transactions were individually committed.

manu jaidka on 1/18/2010
Would like to have more..

Brett Crain on 1/18/2010
Nice video, but I don't agree that you should always check the @@transcount value before committing a transaction. Almost all scenarios that I am familiar with, I would WANT commit transaction to throw an error if there was no open transaction. I would not want to have accidentally forgotten to open a transaction, and then never be notified that my script is non-transactional.

Brett Crain on 1/18/2010
rollback transaction will rollback all changes since the outer-most begin transaction and reset @@trancount back to zero. For instance. begin transaction begin transaction begin transaction rollback transaction -- @@trancount is now zero

73887FE5C9 on 1/19/2010
Good. Why didn't he demonstrate WHILE @@trancount > 0 ?

Leonard Peoples on 1/19/2010
Very helpful. Thank you....

Marc Moshman on 1/21/2010
What's the scope of a rollback? Back to the first 'begin tran' or does it behave like the 'commit tran's?

Team FAB on 1/22/2010
I didn't find it too much - it was fine.

achied on 1/28/2010
very clear and easy to understand...

achied on 1/28/2010
very clear and easy to understand...

Monty on 3/4/2010
Thanks for the great example.

Sanal on 5/9/2011
gud

Jason on 9/26/2011
Good video, would have been nice if you explained how it works if you need to rollback. A single rollback will rollback all transactions.

Chad Segur on 2/12/2012
Very informative, as usual.



Must Be Logged In
 

How Do I Become a Video Author? |  Newsletter History

Copyright © Fourdeuce, Inc., 2005-2009. All Rights Reserved | Privacy Policy | Terms & Conditions