Determine who and what Caused a Deadlock in one of your Database Objects

It is relatively simple to establish what has caused a deadlock in one of your database objects. All you need to do is to know how to manipulate the built in System databases in order to get the appropriate information.

The following Query:

SELECT  SysTL.request_session_id,     DB_NAME(SysTL.resource_database_id),    SysO.Name,     SysP.object_id,     SysTL.resource_type,     SysTL.request_mode,    SysSQLT.text,            SysES.login_name,    SysES.host_name,    SysST.is_user_transaction,,    SysCN.auth_scheme FROM    sys.dm_tran_locks SysTL    JOIN sys.partitions SysP ON SysP.hobt_id = SysTL.resource_associated_entity_id    JOIN sys.objects SysO ON SysO.object_id = SysP.object_id    JOIN sys.dm_exec_sessions SysES ON SysES.session_id = SysTL.request_session_id    JOIN sys.dm_tran_session_transactions SysST ON SysES.session_id = SysST.session_id    JOIN sys.dm_tran_active_transactions SysAT ON SysST.transaction_id = SysAT.transaction_id    JOIN sys.dm_exec_connections SysCN ON SysCN.session_id = SysES.session_id    CROSS APPLY sys.dm_exec_sql_text(SysCN.most_recent_sql_handle) AS SysSQLTWHERE   resource_database_id = db_id()ORDER BY L.request_session_id

Determines which user has caused the lock, on what object is the lock, as well as all associated transactions in the current query?s feed???even the SQL text that is busy executing

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Related Posts