gotchasqlMinor
Why is there a difference between these transaction DMVs in SQL Server 2008 R2?
Viewed 0 times
whythese2008sqldifferencedmvsbetweentransactionserverthere
Problem
When I execute the two queries below,
AND
I've read the BOL for both 1 and 2 but don't see any clear explanation as to why the difference would occur.
I get different results. The former query returns no results, but the latter returns active transactions with session and transaction ids. The
EDIT
I just reran the queries and now I get a result for the first DMV which has a
SELECT
session_id, transaction_id
FROM sys.dm_tran_session_transactions;AND
SELECT
session_id, request_id, at.transaction_id
FROM sys.dm_tran_active_transactions at
JOIN sys.dm_exec_requests r
ON r.transaction_id = at.transaction_id;I've read the BOL for both 1 and 2 but don't see any clear explanation as to why the difference would occur.
I get different results. The former query returns no results, but the latter returns active transactions with session and transaction ids. The
request_id is 0 which, I think, means that it's the only request made by the session. Could someone help me understand why there is a difference between the two concepts I've queried above?EDIT
I just reran the queries and now I get a result for the first DMV which has a
session_id that is not actually contained in the second result set.Solution
It appears that
Using an explicit transaction does return results:
The DMVs are views on internal structures, and the documentation is not often as comprehensive as in other areas. Some of that may be because it would be inconvenient to go through a complete deprecation cycle each time a change in DMV behaviour occurs, but it's likely just an oversight in this case. You could report the documentation deficiency on Connect.
Adam Machanic found all sorts of odd little behaviours with the DMVs while writing his sp_WhoIsActive tool. If it suits your purposes, you could use that rather than trying to write your own monitoring queries.
sys.dm_tran_session_transactions does not include auto-commit transactions:-- No result
SELECT
session_id,
transaction_id
FROM sys.dm_tran_session_transactions;Using an explicit transaction does return results:
BEGIN TRANSACTION;
-- Row returned
SELECT
session_id,
transaction_id
FROM sys.dm_tran_session_transactions;
ROLLBACK TRANSACTION;The DMVs are views on internal structures, and the documentation is not often as comprehensive as in other areas. Some of that may be because it would be inconvenient to go through a complete deprecation cycle each time a change in DMV behaviour occurs, but it's likely just an oversight in this case. You could report the documentation deficiency on Connect.
Adam Machanic found all sorts of odd little behaviours with the DMVs while writing his sp_WhoIsActive tool. If it suits your purposes, you could use that rather than trying to write your own monitoring queries.
Code Snippets
-- No result
SELECT
session_id,
transaction_id
FROM sys.dm_tran_session_transactions;BEGIN TRANSACTION;
-- Row returned
SELECT
session_id,
transaction_id
FROM sys.dm_tran_session_transactions;
ROLLBACK TRANSACTION;Context
StackExchange Database Administrators Q#50837, answer score: 6
Revisions (0)
No revisions yet.