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, 8:15 AM
Nice
Upendra Pratap ShahiPosted Aug 19, 2016, 1:43 PM
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, 4:25 PM
thanks for sharing..
Bhavik PatelPosted Aug 17, 2016, 6:29 PM
Useful