SQL 2005 中有何方法可以找出封鎖的來源


有的。您可以使用 Dynamic Management Views (DMV) 指令碼找出鎖定和封鎖者。

-- script to show blocking and locks
SELECT
  t1.request_session_id AS spid,
  t1.resource_type AS type,
  t1.resource_database_id AS dbid,
  (case resource_type
   WHEN 'OBJECT' THEN object_name(t1.resource_associated_entity_id)
   WHEN 'DATABASE' THEN ' '
   ELSE (SELECT object_name(object_id)
      FROM sys.partitions
      WHERE hobt_id=resource_associated_entity_id)
  END) AS objname,
  t1.resource_description AS description,
  t1.request_mode AS mode,
  t1.request_status AS status,
   t2.blocking_session_id
FROM sys.dm_tran_locks AS t1 LEFT OUTER JOIN sys.dm_os_waiting_tasks AS t2
ON t1.lock_owner_address = t2.resource_address
GO

Comments (0)

Skip to main content