Sql Server查詢最近執行sql

2022-05-15 20:55:11 字數 714 閱讀 4317

由於最近寫了一條sql沒有儲存想重新寫又挺麻煩的,於是想sql server能不能像pl sql一樣ctrl+e就調出了最近在本地執行的sql,結果是不行的。

不過在網上找到了用sql語句查詢最近資料庫執行的sql 也能一用,記得大致日期與sql中用到的表很容易就找出來之前寫的sql。

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

where 1=1

--and qs.creation_time between '2020-02-23 00:00:00' and '2020-02-28 00:00:00' and st.text like '%system_role_type%'

order by qs.creation_time desc

SQLSERVER 執行過的語句查詢

select top30000total worker time 1000as 總消耗cpu 時間 ms execution count 執行次數 qs.total worker time qs.execution count 1000as 平均消耗cpu 時間 ms last execution ...

SQLSERVER 執行過的語句查詢

select top 30000 total worker time 1000 as 總消耗cpu 時間 ms execution count 執行次數 qs.total worker time qs.execution count 1000 as 平均消耗cpu 時間 ms last execut...

SQLSERVER 執行過的語句查詢

select top30000 total worker time 1000as 總消耗cpu 時間 ms execution count 執行次數 qs.total worker time qs.execution count 1000as 平均消耗cpu 時間 ms last execution...