查询数据库锁

 查询数据库锁的根源:

SELECT c.text AS a_sql,a.*,d.text AS b_sql,b.*
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

 

posted @ 2016-09-20 15:41  脸谱匠  阅读(777)  评论(0编辑  收藏  举报