How to Find Recently Executed Queries In SQL Server 2005

Wednesday, 20 May 2009

Today I came across a situation which required to find out recently executed queries to analyse the modifications carried out on a database server.

Here is the query which we used to find out the recently executed queries along with the date and time at which they were executed

SELECT

DMExQryStats.last_execution_time AS [Executed At],

DMExSQLTxt.text AS [Query]

FROM

sys.dm_exec_query_stats AS DMExQryStats

CROSS APPLY

sys.dm_exec_sql_text(DMExQryStats.sql_handle) AS DMExSQLTxt

ORDER BY

DMExQryStats.last_execution_time DESC

Hope this will be useful to you also.

0 comments: