SELECT TOP 10
REPLACE(CONVERT(VARCHAR(20), CONVERT(MONEY,qs.total_worker_time / qs.execution_count/1000),1),'.00','') as [Avg CPU Time(ms)]
,qs.execution_count
,substring (qt.text,
qs.statement_start_offset/2+1,
(case when qs.statement_end_offset = -1 then len (convert (nvarchar(max), qt.text)) * 2
else qs.statement_end_offset end - qs.statement_start_offset)/2) as query_text
,qt.dbid
,sd.name
,qt.objectid
,qt.number
,qt.encrypted
,qt.text
,sr.session_id
,sr.command
,sr.status
,sr.last_wait_type
,sr.wait_resource
,sq.query_plan
,fs.text
FROM sys.dm_exec_query_stats qs
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) as qt
CROSS APPLY sys.dm_exec_query_plan(qs.plan_handle) as sq
LEFT OUTER JOIN sys.databases as sd on qt.dbid = sd.database_id
LEFT OUTER JOIN sys.dm_exec_requests as sr on qs.sql_handle = sr.sql_handle
OUTER APPLY sys.fn_get_sql(sr.sql_handle) AS fs
ORDER BY qs.total_worker_time / qs.execution_count DESC
GO
출처 - 데브피아
'데이터베이스 > MSSQL' 카테고리의 다른 글
MSSQL 2012 ldf 파일 Rebuild 방법(펌) (0) | 2014.01.27 |
---|---|
MSSQL 로그 삭제(2012지원) (0) | 2014.01.27 |
테이블 및 데이터베이스 정렬 변경 (0) | 2013.07.30 |
저장프로시저 암호화 및 뷰 암호화 (0) | 2013.07.02 |
[mssql]저장프로시저 기본 (0) | 2013.06.27 |