查询数据库锁
时间:2021-07-01 10:21:17
帮助过:2人阅读
a.spid,a.blocked,a.waitresource,a.dbid,a.hostname,a.program_name,c.
text AS a_sql
,b.hostname AS b_hostName,b.program_name
AS b_programName,d.
text AS b_sql
FROM sys.sysprocesses a
INNER JOIN sys.sysprocesses b
ON b.spid
=a.blocked
CROSS APPLY sys.dm_exec_sql_text(a.sql_handle) c
CROSS APPLY sys.dm_exec_sql_text(b.sql_handle) d
WHERE a.blocked
<>0
查数据库所有被锁的spid
SELECT * FROM sys.sysprocesses a WHERE a.blocked<>0
查数据库id和name映射
-- 根据name查id
SELECT DB_ID(‘users‘)
-- 根据id查name
SELECT * from sys.databases WHERE database_id=15
查询数据库锁
标签: