sql 查询被锁表id 和导致锁表的语句

工作中遇到了锁表问题 记录一下:

SELECT request_session_id id, OBJECT_NAME(resource_associated_entity_id) tableName
FROM sys.dm_tran_locks
WHERE resource_type=OBJECT

SELECT spid, blocked, DB_NAME(sp.dbid) AS DBName, program_name,
  waitresource, lastwaittype, sp.loginame, sp.hostname, a.[Text] AS 
  [TextData], SUBSTRING ( A. TEXT, sp.stmt_start / 2,
   ( CASE WHEN sp.stmt_end = - 1 THEN DATALENGTH (A. TEXT)
    ELSE sp.stmt_end END - sp.stmt_start ) / 2 ) AS [current_cmd]
     FROM sys.sysprocesses AS sp OUTER APPLY sys.dm_exec_sql_text
      (sp.sql_handle) AS A WHERE spid > 50 ORDER BY blocked DESC,
       DB_NAME(sp.dbid) ASC, a.[text];

 

sql 查询被锁表id 和导致锁表的语句

上一篇:数据库实验系列之3存储过程和触发器实验(至少包括完整的调试通过的8个存储过程和5个触发器)


下一篇:MYSQL注入