SqlServer查詢資料改動歷史記錄

yinghualeihenmei發表於2024-10-23

原文連結:https://blog.csdn.net/qq_40763549/article/details/122229169

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 '2021-12-10 00:00:00'
    and '2021-12-29 23:59:00' 
  -- SQL 語句模糊匹配,如insert、SELECT、UPDATE、DELETE
  and [ST].[text] like '%DELETE%'
order by [QS].[creation_time] desc

  

相關文章