Skip to content

Instantly share code, notes, and snippets.

@hperantunes
Last active June 15, 2017 14:40
Show Gist options
  • Save hperantunes/580030f0d97e2951c35b017aa2bc6572 to your computer and use it in GitHub Desktop.
Save hperantunes/580030f0d97e2951c35b017aa2bc6572 to your computer and use it in GitHub Desktop.
Get all queries executed against the server (SQL Server)
-- Accidently closed an unsaved tab in SQL Server Management Studio, losing my query
-- Found out you can get all queries ran against the server:
SELECT
execquery.last_execution_time AS [Date Time],
execsql.text AS [Script]
FROM
sys.dm_exec_query_stats AS execquery
CROSS APPLY sys.dm_exec_sql_text(execquery.sql_handle) AS execsql
ORDER BY
execquery.last_execution_time DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment