Thursday, March 18, 2010

Get Recently Ran Query - SQL SERVER 2005

Have you ever wanted to see what queries are running in SQL server on the fly? Yes? Well everyone’s favourite SQL server guru Pinalkumar Dave has once again provided the perfect solution with the follow simple SQL script.

SELECT deqs.last_execution_time AS [Time], dest.TEXT AS [Query]
FROM sys.dm_exec_query_stats AS deqs
CROSS APPLY sys.dm_exec_sql_text(deqs.sql_handle) AS dest
ORDER BY deqs.last_execution_time DESC

One thing it doesn’t seem to do is recover last run quires where the database connection/session has finished. Now, Id like to see that as it whould have saved me from the silly mistake of not saving my work :(.

No comments:

Post a Comment