Home » SQL SERVER » SQLSERVER查询最大耗时的前30个语句

SELECT TOP 30
total_worker_time/1000 AS [CPU总耗时(ms)], 
execution_count [运行次数], 
qs.total_worker_time/qs.execution_count/1000 AS [CPU平均耗时(ms)], 
last_execution_time AS [最后执行时间], 
max_worker_time/1000 AS [最大执行耗时(ms)], 
SUBSTRING(qt.text,qs.statement_start_offset/2+1, 
 (CASE WHEN qs.statement_end_offset = -1 
 THEN DATALENGTH(qt.text) 
 ELSE qs.statement_end_offset 
 END -qs.statement_start_offset)/2 + 1) AS [SQL语句]
FROM sys.dm_exec_query_stats qs WITH(nolock)
CROSS apply sys.dm_exec_sql_text(qs.sql_handle) AS qt
WHERE execution_count > 1
ORDER BY max_worker_time DESC

来源:https://blog.csdn.net/jasonijessy/article/details/105375064

标签: SqlServer 数据库卡顿

添加新评论

V