SQL Monitoring
How to see text of the query involved in
September 6th, 2015 4:41pm

Hi j.kumar,

If I understand correctly, you want to know the query which is involved in deadlock.

After testing the issue in my environment, we can use the following query to get the SPID that involved in deadlock:
exec sp_who2
The result set of sp_who2 will contains a column named BlkBy, this represents the SPID that is currently stopping the SPID in the row.

Then we can find the exact query based on the SPID. The following statement is for your reference:
DECLARE @sqltext VARBINARY(128)
SELECT @sqltext = sql_handle
FROM sys.sysprocesses
WHERE spid = (SPID)
SELECT TEXT
FROM sys.dm_exec_sql_text(@sqltext)
GO

If you also want to monitor Deadlocks in SQL Server, please refer to the blog below:
http://blogs.technet.com/b/mspfe/archive/2012/06/28/how_2d00_to_2d00_monitor_2d00_deadlocks_2d00_in_2d00_sql_2d00_server.aspx

Thanks,
Katherine Xiong

Free Windows Admin Tool Kit Click here and download it now
September 7th, 2015 2:52am

thank u Katherine.
September 7th, 2015 11:17pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics