How to get the transaction mode of a spid.

Sam 1,476 Reputation points
2023-02-21T15:19:04.22+00:00

Hi All,

Which DMV will tell me the transaction mode of a SPID?

I did check MSDN but couldn't get the answer.
https://learn.microsoft.com/en-us/sql/relational-databases/system-dynamic-management-views/sys-dm-tran-session-transactions-transact-sql?view=sql-server-ver16

  • Autocommit transaction
  • Implicit transaction
  • Explicit transaction
  • Batch-scoped transaction
  • Distributed transaction

Regards,
Sam

SQL Server | Other
0 comments No comments
{count} votes

Accepted answer
  1. Erland Sommarskog 121.9K Reputation points MVP Volunteer Moderator
    2023-02-21T22:40:28.0166667+00:00

    You can join sys.dm_tran_session_transactions and sys.dm_tran_active_transaction.

    This will give you information whether the transaction is a distributed transaction. I don't think that there is anyway to see the distinction between the first four. (And engine-wise there is not much difference between them.)


1 additional answer

Sort by: Most helpful
  1. Anonymous
    2023-02-22T02:22:24.0566667+00:00

    Hi @Samantha r

    I looked through all the relevant DMVs and found only two columns related to transaction type.

    The sys.dm_tran_active_transactions returns a column named transaction_type that contains four transaction types: read/write transactions, read-only transactions, system transactions, and distributed transactions.

    The sys.dm_tran_database_transactions returns a column named database_transaction_type, which contains read/write transactions, read-only transactions, and system transactions.

    Like Erland said above, there seems to be no way to see the difference between the first four.

    Best regards,

    Percy Tang


    If the answer is the right solution, please click "Accept Answer". If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.