标签:
查询数据库锁的根源:
SELECT 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
标签:
原文地址:http://www.cnblogs.com/icyJ/p/sysprocesses.html