Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Getting Transaction ID Expand / Collapse
Author
Message
Posted Monday, February 11, 2008 12:25 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, April 14, 2008 7:57 AM
Points: 2, Visits: 12
How can I get the Transaction ID inside "BEGIN...COMMIT" commands?

Thank you.

Felipe Melo
Post #454021
Posted Monday, February 11, 2008 7:25 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 6:08 AM
Points: 36,984, Visits: 31,509
WHAT do you mean by "Transaction ID"? Do you mean the level of nesting within the transaction or do you mean the IDENTITY number of a row you just inserted into a table that has an IDENTITY column?

--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #454192
Posted Tuesday, February 12, 2008 6:14 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, April 14, 2008 7:57 AM
Points: 2, Visits: 12
Hi Jeff,

Please corrrect if I'm making any mistake, but I think SQL creates an unique ID to each opened transaction.
If it exist, I need to get this ID number.

Thank you for your reply.
Post #454365
Posted Tuesday, February 12, 2008 6:32 AM
Say Hey Kid

Say Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey Kid

Group: General Forum Members
Last Login: Thursday, August 28, 2008 3:13 AM
Points: 707, Visits: 194
Thats an interesting question, as far as i was aware transaction where managed at the session id, db and object id level.

All this information should be in syslocks, or you could return the session id from @@Spid.

Would interested to know if there is a unique transaction id or guid that is visible and not just internal to SQL.
Post #454377
Posted Tuesday, February 12, 2008 7:22 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 6:08 AM
Points: 36,984, Visits: 31,509
felipe (2/12/2008)
Hi Jeff,

Please corrrect if I'm making any mistake, but I think SQL creates an unique ID to each opened transaction.
If it exist, I need to get this ID number.

Thank you for your reply.


That may be... but that type of thing would go to the transaction log and that particular "transaction ID" doesn't have a public facing interface function that I know of (in plain English... I don't know how to get that number using SQL ;) ).

The only number that I know you can get automatically is if the table has an IDENTITY column. Then you can use the SCOPE_IDENTITY() function to return the ID of the row you last inserted... transaction or not.


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #454413
Posted Tuesday, September 17, 2013 6:21 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, July 22, 2014 5:11 AM
Points: 7, Visits: 45
I know it's a bit late (the thread was opened in 2008!), but here is the answer:

SELECT transaction_id FROM sys.dm_tran_current_transaction;
Post #1495470
Posted Tuesday, September 17, 2013 8:22 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 3:16 PM
Points: 13,301, Visits: 12,159
andrew.whettam (9/17/2013)
I know it's a bit late (the thread was opened in 2008!), but here is the answer:

SELECT transaction_id FROM sys.dm_tran_current_transaction;


This is in the sql 2000 forum. That dmv was not introduced until sql 2005.


_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1495527
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse