查看sqlserver被锁的表以及如何解锁

 
 
查看被锁表:
 
select request_session_id spid,OBJECT_NAME(resource_associated_entity_id) tableName
from sys.dm_tran_locks where resource_type='OBJECT'
 
spid 锁表进程
tableName 被锁表名
 
解锁:
 
declare @spid int
Set @spid = 57 --锁表进程
declare @sql varchar(1000)
set @sql='kill '+cast(@spid as varchar)
exec(@sql)
 
 

select er.session_id, CAST(csql.text AS varchar(255)) AS CallingSQL

from master.sys.dm_exec_requests er WITH (NOLOCK)

CROSS APPLY fn_get_sql (er.sql_handle) csql

where er.session_id =309

 

 

session_id即为spid

 

select * from sys.dm_exec_sessions where session_id in (102,315);

 

exec sp_who 

 

你可能感兴趣的:(sqlserver)