Monday, March 27, 2017

SQL Server - What was the last statement on a session_id




-- What was the statement on a session_idSELECT  c.session_id, t.text,
  QUOTENAME(OBJECT_SCHEMA_NAME(t.objectid, t.dbid)) + '.'  + QUOTENAME(OBJECT_NAME(t.objectid, t.dbid)) proc_name,
  c.connect_time,
  s.last_request_start_time,
  s.last_request_end_time,
  s.status
FROM    sys.dm_exec_connections c
  JOIN    sys.dm_exec_sessions s    ON c.session_id = s.session_id
  CROSS APPLY sys.dm_exec_sql_text(c.most_recent_sql_handle) t
WHERE   c.session_id = 52;--your blocking spid


No comments:

Post a Comment