查询数据库锁的根源:
SELECT c.text AS a_sql,a.*,d.text AS b_sql,b.*FROM sys.sysprocesses aINNER JOIN sys.sysprocesses b ON b.spid=a.blockedCROSS APPLY sys.dm_exec_sql_text(a.sql_handle) cCROSS APPLY sys.dm_exec_sql_text(b.sql_handle) dWHERE a.blocked<>0
查数据库所有被锁的spid
SELECT * FROM sys.sysprocesses a WHERE a.blocked<>0
查数据库id和name映射
-- 根据name查idSELECT DB_ID('users')-- 根据id查nameSELECT * from sys.databases WHERE database_id=15