日期:2014-05-16 浏览次数:20539 次
SELECT DTST.[session_id] ,
DES.[login_name] AS [Login Name] ,
DB_NAME(DTDT.database_id) AS [Database] ,
DTDT.[database_transaction_begin_time] AS [Begin Time] ,
-- DATEDIFF(ms,DTDT.[database_transaction_begin_time], GETDATE()) AS [Durationms],
CASE DTAT.transaction_type
WHEN 1 THEN 'Read/write'
WHEN 2 THEN 'Read-only'
WHEN 3 THEN 'System'
WHEN 4 THEN 'Distributed'
END AS [Transaction Type] ,
CASE DTAT.transaction_state
WHEN 0 THEN 'Not fully initialized'
WHEN 1 THEN 'Initialized, not started'
WHEN 2 THEN 'Active'
WHEN 3 THEN 'Ended'
WHEN 4 THEN 'Commit initiated'
WHEN 5 THEN 'Prepared, awaiting resolution'
WHEN 6 THEN 'Committed'
WHEN 7 THEN 'Rolling back'
WHEN 8 THEN 'Rolled back'
END AS [Transaction State] ,
DTDT.[database_transaction_log_record_count] AS [Log Records] ,
DTDT.[database_transaction_log_bytes_used] AS [Log Bytes Used] ,
DTDT.[database_transaction_log_bytes_reserved] AS [Log Bytes RSVPd] ,
DEST.[text] AS [Last Transaction Text] ,
DEQP.[query_plan] AS [Last Query Plan]
FROM sys.dm_tran_database_transactions DTDT
INNER JOIN sys.dm_tran_session_transactions DTST ON DTST.[transaction_id] = DTDT.[transaction_id]
INNER JOIN sys.[dm_tran_active_transactions] DTAT ON DTST.[transaction_id] = DTAT.[transaction_id]
INNER JOIN sys.[dm_exec_sessions] DES ON DES.[session_id] = DTST.[session_id]
&nb