https://stackoverflow.com/questions/30597429/how-to-clear-cache-of-1-stored-procedure-in-sql-server
--Enter Name of your Procedure. I have used here as 'SP_PrepareCustomers'. You should replace it with the name of your procedure.
DECLARE @NameOfProcedure VARCHAR(255) = 'SP_PrepareCustomers'
DECLARE @planHandle VARBINARY(64) = (SELECT top 1 plan_handle
FROM sys.dm_exec_cached_plans AS cp
CROSS APPLY sys.dm_exec_sql_text(plan_handle)
WHERE cp.cacheobjtype = N'Compiled Plan'
AND cp.objtype = N'Proc'
AND cp.usecounts = 1
AND TEXT LIKE '%' + @NameOfProcedure + '%')
IF @planHandle IS NOT NULL
BEGIN
PRINT 'Procedure with name like ' + @NameOfProcedure + ' plan handle found with value as given below:'
PRINT @planHandle
DBCC FREEPROCCACHE (@planHandle)
PRINT 'Execution plan cleared for the procedure'
END
ELSE
BEGIN
PRINT 'No Plan was found for the selected procedure '
+ @NameOfProcedure
END
Comments