March 18, 2014 at 6:43 am
If I do a BEGIN TRAN I need to do either a ROLLBACK TRAN or a COMMIT TRAN.
How do I now if there is an uncommited transaction?
I ran some code this morning and thought I did the COMMIT TRAN but got pulled away for a couple other tasks. When I got back I could not remember if I did the commit. If I just run COMMIT TRAN it will error if no transaction is open, however there might have been something that I should have done a rollback on.
Thanks
March 18, 2014 at 6:53 am
djj (3/18/2014)
If I do a BEGIN TRAN I need to do either a ROLLBACK TRAN or a COMMIT TRAN.
Yes
How do I now if there is an uncommited transaction?
Check the value of @@TranCount
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
March 18, 2014 at 7:00 am
GilaMonster (3/18/2014)
djj (3/18/2014)
If I do a BEGIN TRAN I need to do either a ROLLBACK TRAN or a COMMIT TRAN.Yes
How do I now if there is an uncommited transaction?
Check the value of @@TranCount
Thank you, my first line was a statement of what I now. However, I had forgotten about the @@TranCount.
Thank you again
March 18, 2014 at 4:47 pm
I prefer using XACT_STATE() rather than @@TRANCOUNT, as it indicates when you must use ROLLBACK rather than COMMIT.
Edit: Of course XACT_STATE() can't tell you whether you have nested trans, but it does tell you if the current transaction cannot be committed.
SQL DBA,SQL Server MVP(07, 08, 09) A socialist is someone who will give you the shirt off *someone else's* back.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply