查看SQL Server數據庫被鎖表及解鎖操作


1.查看被鎖表:

select request_session_id spid,OBJECT_NAME(resource_associated_entity_id) tableNamefrom 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)


--查詢出死鎖的SPID

select blocked
from (select * from sysprocesses where blocked>0 ) a
where not exists(select * from (select * from sysprocesses where blocked>0 ) b
where a.blocked=spid)


--輸出引起死鎖的操作
DBCC INPUTBUFFER (@spid)


--查詢當前進程數
select count(-1) from sysprocesses
where dbid in (select dbid from sysdatabases where name like '%telcount%');

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM