執行次數最多的sql語句


執行次數最多的sql語句

SELECT top 50 * FROM 
(
    SELECT top 1000 creation_time  N'語句編譯時間'
            ,DB_NAME(st.dbid) AS dbname
            ,OBJECT_NAME(st.objectid) AS objectname
            ,last_execution_time  N'上次執行時間'
            ,execution_count/(CASE WHEN DATEDIFF(mi,creation_time,getdate())=0 THEN 1 ELSE DATEDIFF(mi,creation_time,getdate()) END)  as 'count/minute'            
            ,datediff(mi,creation_time,getdate()) as 'minute'    
            --,total_physical_reads N'物理讀取總次數'
            --,total_logical_reads/execution_count N'每次邏輯讀次數'
            --,total_logical_reads  N'邏輯讀取總次數'
            --,total_logical_writes N'邏輯寫入總次數'
            ,execution_count  N'執行次數'
            --,total_worker_time/1000 N'所用的CPU總時間ms'
            --,total_elapsed_time/1000  N'總花費時間ms'
            --,(total_elapsed_time / execution_count)/1000  N'平均時間ms'
            ,SUBSTRING(st.text, (qs.statement_start_offset/2) + 1,
             ((CASE statement_end_offset
              WHEN -1 THEN DATALENGTH(st.text)
              ELSE qs.statement_end_offset END
                - qs.statement_start_offset)/2) + 1) N'執行語句'
            ,st.text
    FROM sys.dm_exec_query_stats AS qs
    CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) st
    where SUBSTRING(st.text, (qs.statement_start_offset/2) + 1,
             ((CASE statement_end_offset
              WHEN -1 THEN DATALENGTH(st.text)
              ELSE qs.statement_end_offset END
                - qs.statement_start_offset)/2) + 1) not like '%fetch%' 
                --and text not like '%sp_ms%'
                --and qs.execution_count>100 and
               -- (total_elapsed_time / execution_count)/1000>150
    --ORDER BY  'count/minute' DESC;
    ORDER BY   execution_count DESC
)
t ORDER BY 'count/minute' DESC

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM