是否有人知道检查SQL Server 2005中是否存在未提交事务的命令?
答案 0 :(得分:39)
在sql 2005,2008中使用@@trancount或sys.dm_tran_active_transactions DMV
答案 1 :(得分:24)
XACT_STATE()报告会话的事务状态,指示会话是否具有活动事务,以及事务是否能够提交。它返回三个值:
@@ TRANCOUNT 返回当前连接的活动事务数。
答案 2 :(得分:7)
运行
DBCC OPENTRAN
答案 3 :(得分:5)
SELECT
trans.session_id AS [SESSION ID],
ESes.host_name AS [HOST NAME],login_name AS [Login NAME],
trans.transaction_id AS [TRANSACTION ID],
tas.name AS [TRANSACTION NAME],tas.transaction_begin_time AS [TRANSACTION BEGIN TIME],
tds.database_id AS [DATABASE ID],DBs.name AS [DATABASE NAME]
FROM sys.dm_tran_active_transactions tas
JOIN sys.dm_tran_session_transactions trans
ON (trans.transaction_id=tas.transaction_id)
LEFT OUTER JOIN sys.dm_tran_database_transactions tds
ON (tas.transaction_id = tds.transaction_id )
LEFT OUTER JOIN sys.databases AS DBs
ON tds.database_id = DBs.database_id
LEFT OUTER JOIN sys.dm_exec_sessions AS ESes
ON trans.session_id = ESes.session_id
WHERE ESes.session_id IS NOT NULL
- 仅当SELECT @@ TRANCOUNT命令execute.otherwise NULL
时才会获得DB名称执行上面的代码...将给出事务发生的会话详细信息..
答案 4 :(得分:2)
总而言之,有几种方法:
答案 5 :(得分:0)
sp_who2 sp_lock的