--查看被鎖定表:
SELECT request_session_id spid, OBJECT_NAME( resource_associated_entity_id ) tableName FROM sys.dm_tran_locks WHERE resource_type = 'OBJECT' ORDER BY request_session_id ASC --spid 锁表进程 --tableName 被锁表名
--根據鎖定表程序查詢對應程序互鎖的SQL語句
DBCC INPUTBUFFER (249)
# --解鎖:
DECLARE @spid INT SET @spid = 52--锁表进程 DECLARE @SQL VARCHAR (1000) SET @SQL = 'kill ' + CAST (@spid AS VARCHAR) EXEC (@SQL)
--產生解鎖SQL
SELECT DISTINCT 'DECLARE @spid INT SET @spid = ',request_session_id,' DECLARE @SQL VARCHAR (1000) SET @SQL = ''kill '' + CAST (@spid AS VARCHAR) EXEC (@SQL);' as s FROM sys.dm_tran_locks WHERE resource_type = 'OBJECT' --spid 锁表进程 --tableName 被锁表名
以上是sqlserver查詢鎖住sql以及解鎖的方法的詳細內容。更多資訊請關注PHP中文網其他相關文章!