Get Latest Executed Queries In SQL Server

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 
  1. SELECT  
  2. deqs.last_execution_time AS [Time],   
  3. dest.TEXT AS [Query]  
  4. FROM   
  5. sys.dm_exec_query_stats AS deqs  
  6. CROSS APPLY sys.dm_exec_sql_text(deqs.sql_handle) AS dest  
  7. ORDER BY   
  8. deqs.last_execution_time DESC   
Example