5

I was wondering if there is a way to find out the number of active locks held on a table in SQL Server?

1

1 Answer 1

12

Here is a start. Remember that locks can go parallel so you may see the same object being locked on multiple resource_lock_partition values.

USE yourdatabase;
GO

SELECT * FROM sys.dm_tran_locks
  WHERE resource_database_id = DB_ID()
  AND resource_associated_entity_id = OBJECT_ID(N'dbo.yourtablename');

Please look at the documentation for sys.dm_tran_locks

1
  • 1
    I I just noticed that the above answer gives the number of locks on the table but does not give locks on pages and entities on that table. Is there a way to get those locks as well? Apr 5, 2013 at 21:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.