Sometimes, we need to get all the queries which have been executed recently in the database. Using the query, given below, you can get the list of the recently executed queries.
Syntax
- 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
Example