Top 100 Ad Hoc statements

Last updated:

Warning: Review and test in a non-production environment before running.

Back to results

-- Adapted from demo scripts by Kimberly L. Tripp, SQLskills – https://www.sqlskills.com/blogs/kimberly/

SELECT TOP (100) [st].[text]
    , [cp].[size_in_bytes]
    , [cp].[plan_handle]
FROM [sys].[dm_Exec_cached_plans] AS [cp]
    CROSS APPLY [sys].[dm_exec_sql_text]
         ([cp].[plan_handle]) AS [st]
WHERE [cp].[objtype] = N'Adhoc' 
    AND [cp].[usecounts] = 1
ORDER BY [cp].[size_in_bytes] DESC;