SQL SERVER – How to Identify Locked Table in SQL Server?

Here is a quick script which will help users to identify locked tables in the SQL Server.

SELECT
OBJECT_NAME(p.OBJECT_ID) AS TableName,
resource_type, resource_description
FROM
sys.dm_tran_locks l
JOIN sys.partitions p ON l.resource_associated_entity_id = p.hobt_id

When you run above script, it will display table name and lock on it.

I have written code to lock the person table in the database. After locking the database, when I ran above script – it gave us following resultset.

SQL SERVER - How to Identify Locked Table in SQL Server? lock

Reference: Pinal Dave (https://darkslategrey-bat-805937.hostingersite.com)

Previous Post
SQL SERVER – Unable to Bring SQL Cluster Resource Online – Online Pending and then Failed
Next Post
Interview Question of the Week #032 – Best Practices Around FileGroups

Related Posts

No results found.

Leave a Reply