在园子找到了答案(人人都是 DBA(XII)查询信息收集脚本汇编),而且贴心地将 total_elapsed_time 换算成了秒。
SELECT TOP 10 TEXT AS 'SQL Statement' ,last_execution_time AS 'Last Execution Time' ,(total_logical_reads + total_physical_reads + total_logical_writes) / execution_count AS [Average IO] ,(total_worker_time / execution_count) / 1000000.0 AS [Average CPU Time (sec)] ,(total_elapsed_time / execution_count) / 1000000.0 AS [Average Elapsed Time (sec)] ,execution_count AS "Execution Count" ,qp.query_plan AS "Query Plan" FROM sys.dm_exec_query_stats qs CROSS APPLY sys.dm_exec_sql_text(qs.plan_handle) st CROSS APPLY sys.dm_exec_query_plan(qs.plan_handle) qp ORDER BY total_elapsed_time / execution_count DESC
查看执行慢的存储过程,可以看这位博主的另外一篇博文:人人都是 DBA(XIV)存储过程信息收集脚本汇编
6+
如果你觉得数据库执行查询慢,可以建立索引或存储过程、视图来优化查询
优化查询流程,善于使用子查询,建立视图。