Created
July 6, 2017 17:59
-
-
Save tcartwright/dcacdf46d2c20466c243aad429666503 to your computer and use it in GitHub Desktop.
SQL SERVER: Clear single use plans from cache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DECLARE @Sql VARCHAR(MAX) = ( | |
SELECT 'DBCC FREEPROCCACHE (0x' + CONVERT( VARCHAR(MAX), [ecp].[plan_handle], 2) + ') WITH NO_INFOMSGS; ' + CHAR(10) | |
FROM [sys].[dm_exec_cached_plans] [ecp] | |
WHERE [ecp].[usecounts] = 1 | |
AND [ecp].[objtype] IN('Adhoc', 'Prepared') | |
FOR XML PATH('') | |
); | |
SELECT @sql | |
--EXEC (@sql) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment