查询sqlserver执行的sql脚本

SELECT total_elapsed_time/1000/execution_count AS [Avg CPU Time],
    execution_count  AS [Exec Count],
total_worker_time/1000  AS [Total time],
total_elapsed_time/1000 AS [Elapse time],
creation_time AS [Create time],
    SUBSTRING(st.text, (qs.statement_start_offset/2)+1,
        ((CASE qs.statement_end_offset
          WHEN -1 THEN DATALENGTH(st.text)
         ELSE qs.statement_end_offset
         END - qs.statement_start_offset)/2) + 1) AS [statement_text]
FROM sys.dm_exec_query_stats AS qs
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) AS st
WHERE creation_time > '2016-10-19 19:55:00' and (st.text like '% CI %' or st.text like '% Attribute %')
ORDER BY total_elapsed_time DESC;

--DBCC FREEPROCCACHE

你可能感兴趣的:(sql)