Tuesday, October 11, 2016

SQL: 查找某段時間所執行的query

SELECT
    deqs.last_execution_time AS [Time],
    dest.TEXT AS [Query]
FROM
    sys.dm_exec_query_stats AS deqs
    CROSS APPLY sys.dm_exec_sql_text(deqs.sql_handle) AS dest
WHERE deqs.last_execution_time >= '20161005' and deqs.last_execution_time <= '20161007'
ORDER BY deqs.last_execution_time DESC
Reference: Find all the queries executed recently on a database

No comments: