SQLServer 查询近期执行的sql语句
作者:互联网
SELECT TOP 1000
QS.creation_time AS '执行时间' ,
QS.total_elapsed_time/1000 AS '耗时',
QS.total_rows,
SUBSTRING(ST.text,qs.statement_start_offset/2+1,
(CASE WHEN qs.statement_end_offset = -1
THEN DATALENGTH(ST.text)
ELSE qs.statement_end_offset END -qs.statement_start_offset)/2 + 1)
AS [使用CPU的语法],
-- ST.text AS '执行的SQL语句',
QS.execution_count AS '执行次数',
QS.total_logical_reads AS '逻辑读取次数',
QS.total_logical_writes AS '逻辑写入次数',
QS.total_physical_reads AS '物理读取次数',
QS.*
FROM sys.dm_exec_query_stats QS
CROSS APPLY
sys.dm_exec_sql_text(QS.sql_handle) ST
WHERE QS.creation_time BETWEEN '2022-07-03 19:17:15' AND '2022-09-02 17:52:15' --and st.text like '%MERGE%'
and SUBSTRING(ST.text,qs.statement_start_offset/2+1,
(CASE WHEN qs.statement_end_offset = -1
THEN DATALENGTH(ST.text)
ELSE qs.statement_end_offset END -qs.statement_start_offset)/2 + 1) like 'update %' --sql语句
ORDER BY
QS.creation_time DESC
标签:语句,QS,text,offset,SQLServer,qs,ST,statement,sql 来源: https://www.cnblogs.com/nuomibaibai/p/16650055.html