09-sp_lock and usage sys.dm_tran_locks

A summary

1. URL

https://docs.microsoft.com/zh-cn/sql/relational-databases/system-stored-procedures/sp-lock-transact-sql?redirectedfrom=MSDN&view=sql-server-2017(sp_lock)
https://docs.microsoft.com/zh-cn/sql/relational-databases/system-dynamic-management-views/sys-dm-tran-locks-transact-sql?view=sql-server-2017(sys.dm_tran_locks)

2. identify the specific meaning of the results refer to the official documentation

Second, the use of SQL

1. The view object name object_id
commands: SELECT the OBJECT_NAME (245 575 913)
           the SELECT the OBJECT_ID ( 'run.dbo.T1')

   

 

 2. Query all the locks

Command: exec sp_lock

 

 

3. Query specified process lock
command: exec sp_lock 55

 

 

4. The system view query specified process lock
command: select * from sys.dm_tran_locks where request_session_id = 55

 

 

The display of a library lock information, parameters dbid
command: the SELECT resource_type, resource_associated_entity_id,
request_status, request_mode, request_session_id,
resource_description
the FROM the sys.dm_tran_locks
the WHERE resource_database_id. 5 =

6.显示阻塞信息
命令:SELECT
t1.resource_type,
t1.resource_database_id,
t1.resource_associated_entity_id,
t1.request_mode,
t1.request_session_id,
t2.blocking_session_id
FROM sys.dm_tran_locks as t1
INNER JOIN sys.dm_os_waiting_tasks as t2
ON t1.lock_owner_address = t2.resource_address;

 

Guess you like

Origin www.cnblogs.com/jialanyu/p/11578279.html