日期:2014-05-17  浏览次数:20337 次

查找占用upu 最多的一些脚本
/*------------------------------------------+ 
#| = : = : = : = : = : = : = : = : = : = : = : = : = : = : = : = : = : = : = :  | 
#|{>/------------------------------------\<}| 
#|: | Author???? :??? ?小爱(Beirut)??????????????????????????                               | 
#|: | Description:????查找占用upu 最多的一些脚本                             ?    |
#|: | SQL Version:????适用于 SQL 2012, SQL 2008 R2, SQL 2008????????????????????        |
#|: | Copyright??:??  免费使用和共享e ????/^(o.o)^\???????????????????????????            ? |
#|: | Create Date:????2012-04-13 16:50:20.577? ???????????????????????????                 |
#|: | Revision???? :? ?Version: 1.1 持续更新ing ?                                  |
#|{>\------------------------------------/<}| 
#| = : = : = : = : = : = : = : = : = : = : = : = : = : = : = : = : = : = : = :? ?| 
#+-----------------------------------------*/ 

select GETDATE()
use tempdb
go
IF object_id('tempdb..#FindTopCPUQueries_set1') is not null DROP TABLE [dbo].[#FindTopCPUQueries_set1]
GO
declare @ServerTime datetime = getdate()
, @ConvertMiliSeconds bigint = 1000
, @FilterMoreThanMiliSeconds bigint = 1
, @FilterHours bigint = 2
, @execution_count bigint = 2
, @debugFlg bit = 0


if @debugFlg=1 
select @ServerTime as ServerTime, @ConvertMiliSeconds as ConvertMiliSeconds
, @FilterMoreThanMiliSeconds as FilterMoreThanMiliSeconds, @FilterHours as FilterHours 
, @execution_count as execution_count

select top 300 @@servername as servername,@ServerTime as runtime
,isnull(db_name(QueryText.dbid),'PreparedSQL') as DBName
,SUBSTRING(QueryText.text,(QueryStats.statement_start_offset/2)+1,
    (isnull((
                CASE QueryStats.statement_end_offset 
                WHEN -1 THEN DATALENGTH(QueryText.text)
                WHEN 0 THEN DATALENGTH(QueryText.text)