sql server last executed query

Solutions on MaxInterview for sql server last executed query by the best coders in the world

showing results for - "sql server last executed query"
Emmanuelle
04 Jan 2020
1SELECT deqs.last_execution_time AS [Time], dest.text AS [Query], dest.*
2FROM sys.dm_exec_query_stats AS deqs
3CROSS APPLY sys.dm_exec_sql_text(deqs.sql_handle) AS dest
4WHERE dest.dbid = DB_ID('msdb')
5ORDER BY deqs.last_execution_time DESC
6
7SELECT dest.TEXT AS [Query],
8deqs.execution_count [Count],
9deqs.last_execution_time AS [Time]
10FROM sys.dm_exec_query_stats AS deqs
11CROSS APPLY sys.dm_exec_sql_text(deqs.sql_handle) AS dest
12ORDER BY deqs.last_execution_time DESC