select * from sys.dm_tran_locks where resource_type = 'OBJECT' and resource_database_id = 31
其中31代表是数据库ID,可以使用DB_ID()获取
从返回的结果中获取到request_session_id,这个就是会话ID,也就是SPWHO中的spid,
resource_associated_entity_id代表的是事务执行的表的ID,使用OBJECT_NAME函数获取,
select OBJECT_NAME(sys.dm_tran_locks.resource_associated_entity_id) from sys.dm_tran_locks where resource_type = 'OBJECT' and resource_database_id = 31
然后使用kill终止会话即可。