如何清除 SQL Server 2005/2008 中的查询执行统计信息 [英] How to Clear down Query Execution Statistics in SQL Server 2005/2008

查看:84
本文介绍了如何清除 SQL Server 2005/2008 中的查询执行统计信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基于使用从这篇文章中获得的这段极其有用的 SQL 获取查询执行统计数据最常执行的存储过程 - 堆栈溢出:

Based on getting Query Execution Statistics using this extremely useful piece of SQL obtained from this post Most Executed Stored Procedure - Stack Overflow:

SELECT TOP 100
   qt.TEXT AS 'SP Name',
   SUBSTRING(qt.text, qs.statement_start_offset/2, CASE WHEN (qs.statement_end_offset = -1) THEN LEN(qt.text) ELSE (qs.statement_end_offset - qs.statement_start_offset)/2 END) AS actual_query,
   qs.execution_count AS 'Execution Count',
   qs.total_worker_time/qs.execution_count AS 'AvgWorkerTime',
   qs.total_worker_time AS 'TotalWorkerTime',
   qs.total_physical_reads AS 'PhysicalReads',
   qs.creation_time 'CreationTime',
   qs.execution_count/DATEDIFF(Second, qs.creation_time, GETDATE()) AS 'Calls/Second'
FROM sys.dm_exec_query_stats AS qs
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) AS qt
WHERE qt.dbid = (SELECT dbid
                FROM sys.sysdatabases
               WHERE name = 'BSP')
ORDER BY qs.total_worker_time/qs.execution_count DESC

如何彻底清除这些执行统计信息并从头开始?

How would I completely clear out these execution statistics and start from scratch?

这将特别有用,因为开发错误和测试导致例程通常被调用大量次数,从而使真实使用级别无效.

This would be particularly useful as development bugs and testing have caused routines to be called an usually large number of times thus invaliding the true usage levels.

推荐答案

DBCC FREEPROCCACHE
DBCC DROPCLEANBUFFERS

这篇关于如何清除 SQL Server 2005/2008 中的查询执行统计信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆