Thursday, April 25, 2019

recover old sql server query

SELECT top 50 t.[text], s.last_execution_time
FROM sys.dm_exec_cached_plans AS p
INNER JOIN sys.dm_exec_query_stats AS s
   ON p.plan_handle = s.plan_handle
CROSS APPLY sys.dm_exec_sql_text(p.plan_handle) AS t
WHERE t.[text] LIKE N'%insert into tbl_Keyword%'
ORDER BY s.last_execution_time DESC;


SELECT t.[text], s.last_execution_time
FROM sys.dm_exec_cached_plans AS p
INNER JOIN sys.dm_exec_query_stats AS s
   ON p.plan_handle = s.plan_handle
CROSS APPLY sys.dm_exec_sql_text(p.plan_handle) AS t
WHERE convert(varchar(8), last_execution_time , 112) = '20190429'
ORDER BY s.last_execution_time DESC;

No comments:

Post a Comment