SQL SERVER發生死鎖檢測語句
阿新 • • 發佈:2018-12-12
sql server資料庫發生死鎖採用如下SQL語句進行檢索:
select object_name(resource_associated_entity_id) as tableName, request_session_id as pid from sys.dm_tran_locks where resource_type = ‘OBJECT’
SELECT * FROM sys.dm_exec_connections;
SELECT * FROM sys.dm_exec_sessions;
SELECT spid, blocked, DB_NAME(sp.dbid) AS DBName, program_name, waitresource, lastwaittype, sp.loginame, sp.hostname, a.[Text] AS [TextData], SUBSTRING ( A. TEXT, sp.stmt_start / 2, ( CASE WHEN sp.stmt_end = - 1 THEN DATALENGTH (A. TEXT) ELSE sp.stmt_end END - sp.stmt_start ) / 2 ) AS [current_cmd] FROM sys.sysprocesses AS sp OUTER APPLY sys.dm_exec_sql_text (sp.sql_handle) AS A WHERE spid > 50 ORDER BY blocked DESC, DB_NAME(sp.dbid) ASC, a.[text];
殺掉死鎖方法: kill id