• 查询SQLSERVER执行过的SQL记录


    仅支持SQL SERVER2008及以上版本

    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 ‘2018-05-08 09:00:00’ AND ‘2018-05-08 18: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 ‘2018-05-08 09:00:00’ AND ‘2018-05-08 18:00:00’
    AND ST.text NOT LIKE ‘%SELECT * FROM T_LOCATIONINFO WHERE STRCLIPLOGICID in(%’
    ORDER BY
    QS.creation_time DESC

  • 相关阅读:
    xt
    UVA 10200 Prime Time (打表)
    CodeForces 540B School Marks
    CodeForces 540C Ice Cave (BFS)
    poj 3250 Bad Hair Day(栈的运用)
    hdu A Magic Lamp
    hdu 4325 Flowers(区间离散化)
    hdu 5500 Reorder the Books
    V2X之标准
    V2X的前生今世
  • 原文地址:https://www.cnblogs.com/lllini/p/11955219.html
Copyright © 2020-2023  润新知