Skip to content

Instantly share code, notes, and snippets.

@nire0510
Last active March 27, 2018 10:19
Show Gist options
  • Save nire0510/da3150a55d1a6580db93 to your computer and use it in GitHub Desktop.
Save nire0510/da3150a55d1a6580db93 to your computer and use it in GitHub Desktop.
[Last Executions] Get the last executed queries for a specific database #database #ms-sql
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment