nire0510
12/29/2014 - 7:33 AM

Get the last executed queries for a specific database

Get the last executed queries for a specific database

SELECT deqs.last_execution_time AS [Time],
  dest.text AS [Query], dest.*
FROM sys.dm_exec_query_stats AS deqs
  CROSS APPLY sys.dm_exec_sql_text(deqs.sql_handle) AS dest
WHERE dest.dbid = DB_ID('DB_NAME')
ORDER BY deqs.last_execution_time DESC