今天出現一個奇怪的現象,SQLServer資料庫中某張表的隻有8條資料,在Navicat中執行SQL語句,十幾秒都沒有結果
資料庫的其他表均能正常顯示。網上調查得知可能是表出現死鎖情況
解決方案如下:
1.檢視被鎖表:
select request_session_id spid,OBJECT_NAME(resource_associated_entity_id) tableName
from sys.dm_tran_locks where resource_type='OBJECT'
spid 代表鎖表程序
tableName 代表被鎖表名
2.解鎖:
declare @spid int
Set @spid = 57 --鎖表程序
declare @sql varchar(1000)
set @sql='kill '+cast(@spid as varchar)
exec(@sql)
将 57改為對應的鎖表程序即可
參考文章
出現死鎖的原因