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?
The data in
sys.dm_exec_query_statsis 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.