简体   繁体   English

SQL Server 2005查询历史记录

[英]SQL Server 2005 Query History

I can easily see a list of recently run queries using the following SQL: 我可以使用以下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. 此查询返回8,500行 - 今天针对数据库执行的所有查询。

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_stats is reset every time SQL Server is restarted. 每次重新启动SQL Server时,都会重置sys.dm_exec_query_stats的数据。 So if you're only seeing a day's worth of data, the server must have been reset about that long ago. 因此,如果您只看到一天的数据,那么服务器必须在很久以前就已经重置了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM