How to Check SQL Server Query History

The key to this question for me is the word “good”. There are a lot of alternatives to SQL Server Management Studio. We can start with the command line as one alternative. However, would anyone ever describe managing their SQL Server instance only from the command line as “good”? Probably not. Especially when we consider this is supposed to be a list of “alternatives” not additional tools. Because, I’d surely add the command line, or better still, Powershell, to my use of SSMS. I just wouldn’t replace SSMS with PowerShell as an alternative.

How to Check SQL Server Query History

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 t.[text] LIKE N'%something unique about your query%'
ORDER BY s.last_execution_time DESC;

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

© 2024 Digital Trends - WordPress Theme by WPEnjoy