Listing Locked Tables in SQL Server

Hello to everyone,

In this article, I will try to give information about listing locked tables in SQL Server.

In SQL Server you may want to list locked tables in some cases.

You can easily do this using the code below.

SELECT STR(request_session_id, 4, 0) AS spid,
       CONVERT(VARCHAR(12), DB_NAME(resource_database_id)) AS db_name,
           WHEN resource_database_id = DB_ID()
                AND resource_type = 'OBJECT' THEN
               CONVERT(CHAR(20), OBJECT_NAME(resource_associated_entity_id))
               CONVERT(CHAR(20), resource_associated_entity_id)
       END AS object,
       CONVERT(VARCHAR(12), resource_type) AS resrc_type,
       CONVERT(VARCHAR(12), request_type) AS req_type,
       CONVERT(CHAR(1), request_mode) AS mode,
       CONVERT(VARCHAR(8), request_status) AS status
FROM sys.dm_tran_locks
ORDER BY request_session_id,
         3 DESC;

You can get all locked tables listed by running the above code.

Good luck to everyone in business and life.


Yavuz Selim Kart

I try to explain what I know in software and database. I am still improving myself by doing research on many programming languages. Apart from these, I am also interested in Graphic Design and Wordpress. I also have knowledge about SEO and Social media management. In short, I am a determined person who likes to work hard.

You may also like...

Don`t copy text!