Saturday, April 6, 2013

Know the last executed Statement in Sql Server

Sometime to do analysis on locking, blocking, or other maintenance activities we need to get the information on last executed statements (queries) in our database.

So to get the list of executed statement you can run this query


SELECT TOP 10
t.TEXT QueryName,
last_elapsed_time
FROM sys.dm_exec_query_stats s
CROSS APPLY sys.dm_exec_sql_text( s.sql_handle ) t
ORDER BY last_execution_time DESC


Post a Comment