SQL查詢日誌 檢視資料庫歷史查詢記錄的方法
阿新 • • 發佈:2019-01-05
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 '2012-01-01 00:00:00' AND '2013-02-28 00:00:00'
AND ST.text LIKE '%%'
ORDER BY
QS.creation_time DESC
--建立時間
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 '2012-01-01 00:00:00' AND '2013-02-28 00:00:00'
AND ST.text LIKE '%%'
ORDER BY
QS.creation_time DESC