SELECT r.session_id,
s.login_name,
r.status,
blocking_session_id,
blocks.login_name AS blockingLoginName,
blocks.open_transaction_count AS blockingOpenTransCount,
blocks.status AS blockingSessionStatus,
r.start_time,
s.client_interface_name,
s.host_name,
wait_type, wait_time, wait_resource, transaction_id, r.command,
r.database_id,
DB_NAME(r.database_id) as 数据库,
CONVERT(DECIMAL(10, 2), r.estimated_completion_time / 1000.0 / 60.0 / 60.0) AS [ETA hours],
CONVERT(NVARCHAR(max), (SELECT text FROM sys.dm_exec_sql_text(sql_handle) )) AS 脚本
FROM sys.dm_exec_requests r
LEFT JOIN sys.dm_exec_sessions blocks ON r.blocking_session_id=blocks.session_id
LEFT JOIN sys.dm_exec_sessions s ON r.session_id=s.session_id
WHERE 1=1 AND(r.status IN (N’suspended’, N’running’)OR blocking_session_id<>0)
MSSQL查询数据库锁表
最新推荐文章于 2024-05-27 16:05:38 发布