Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server 2005 Query History

I can easily see a list of recently run queries using the following SQL:

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
ORDER BY    deqs.last_execution_time DESC

This query returns 8,500 rows - all queries executed against the DB today.

Question: Is there any way to see the queries run against the DB for the entire week? How about for a specific day?

like image 219
James Hill Avatar asked Nov 04 '22 12:11

James Hill


1 Answers

The data in sys.dm_exec_query_stats is reset every time SQL Server is restarted. So if you're only seeing a day's worth of data, the server must have been reset about that long ago.

like image 127
Yuck Avatar answered Nov 09 '22 15:11

Yuck