Search

Thursday, August 4, 2011

Get Latest SQL Query for Sessions – DMV

How can one figure out what was the last SQL Statement executed in sessions.
The query for this is very simple. It uses two DMVs and created following quick script for the same.

SELECT session_id, TEXT
FROM sys.dm_exec_connections
CROSS APPLY sys.dm_exec_sql_text(most_recent_sql_handle) AS ST



No comments:

Post a Comment