본문 바로가기

DataBase/MS-SQL

실행된 쿼리내역 조회

반응형

SELECT

  db_name(st.dbid) DBName

, qs.total_elapsed_time

, creation_time

, last_execution_time

, text

FROM sys.dm_exec_query_stats AS  qs CROSS APPLY sys.dm_exec_sql_text(qs.plan_handle) AS st

INNER JOIN sys.dm_exec_cached_plans AS cp

 ON qs.plan_handle = cp.plan_handle

WHERE creation_time >= '2010-01-01 00:00:00' 

--AND db_name(st.dbid) is not null and cp.objtype = 'proc' --조건: 종류

AND text LIKE '%delete%' ORDER BY last_execution_time DESC

;

반응형