• 数据库查询历史执行过的sql语句


    平常的调试过程中可能想查询以前执行过的语句。以下为sqlserver2008中查询历史执行语句。

    SELECT TOP 1000 
    --创建时间 
    QS.creation_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, 
    --执行文本 
    ST.text, 
    --执行计划 
    QS.total_worker_time, 
    QS.last_worker_time, 
    QS.max_worker_time, 
    QS.min_worker_time 
    FROM 
    sys.dm_exec_query_stats QS 
    --关键字 
    CROSS APPLY 
    sys.dm_exec_sql_text(QS.sql_handle) ST 
    WHERE 
    QS.creation_time BETWEEN '2017-1-03 09:00:00' AND '2017-12-03 11:00:00' 
    --AND ST.text LIKE '%%' 
    ORDER BY 
    QS.creation_time DESC
    
    
    SELECT TOP 1000 
    --创建时间 
    QS.creation_time, 
    --执行文本 
    ST.text
    FROM 
    sys.dm_exec_query_stats QS 
    --关键字 
    CROSS APPLY 
    sys.dm_exec_sql_text(QS.sql_handle) ST 
    WHERE 
    QS.creation_time BETWEEN '2017-1-03 09:00:00' AND '2017-12-03 11:00:00' 
    AND ST.text NOT LIKE '%SELECT * FROM T_LOCATIONINFO WHERE STRCLIPLOGICID in(%' 
    ORDER BY 
    QS.creation_time DESC
  • 相关阅读:
    openmp
    opencv 读写矩阵
    string to const char*
    c++ string to number
    HDU 1520 Anniversary Party
    ZOJ 1003 Crashing Balloon
    HDU 4171 Paper Route
    ZOJ 2067 White Rectangles
    TOJ 1690 Cow Sorting (置换群)
    TOJ 2814 Light Bulb
  • 原文地址:https://www.cnblogs.com/musexiaoluo/p/6864225.html
Copyright © 2020-2023  润新知