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


SubashPosted Sep 7, 2016, 4:15 AM EDT
Nice
Upendra Pratap ShahiPosted Aug 19, 2016, 9:43 AM EDT
It's giving permission issue as "Msg 297, Level 16, State 1, Line 1The user does not have permission to perform this action. "
Upendra Pratap ShahiPosted Aug 18, 2016, 12:25 PM EDT
thanks for sharing..
Bhavik PatelPosted Aug 17, 2016, 2:29 PM EDT
Useful