FREEPROCCACHE - Execution Plans

To clean up the execution plan:

 

-- Example 3 (Scalpel)

-- Remove one plan from the cache

-- Get the plan handle for a cached plan

SELECT cp.plan_handle, st.[text]

FROM sys.dm_exec_cached_plans AS cp

CROSS APPLY sys.dm_exec_sql_text(plan_handle) AS st

WHERE [text] LIKE N'%auditbase%';

 

-- Remove the specific plan from the cache using the plan handle

DBCC FREEPROCCACHE (0x06000B002F8C0A2140400E020200000001000000000000000000000000000000000000000000000000000000);

 

 

 

SELECT concat('DBCC FREEPROCCACHE (',convert(varchar(255),cp.plan_handle),');')

FROM sys.dm_exec_cached_plans AS cp

CROSS APPLY sys.dm_exec_sql_text(plan_handle) AS st

WHERE [text] LIKE N'%auditbase%';

 

DBCC FREEPROCCACHE (

 

 

 

DECLARE @intDBID INT;

SET @intDBID = (SELECT [dbid]

                FROM master.dbo.sysdatabases

                WHERE name = 'TurnersGroup_MSCRM');

 

-- Flush the procedure cache for one database only

DBCC FLUSHPROCINDB (@intDBID);

 

 

-- Example 3 (Scalpel)

-- Remove one plan from the cache

-- Get the plan handle for a cached plan

SELECT cp.plan_handle, st.[text]

FROM sys.dm_exec_cached_plans AS cp

CROSS APPLY sys.dm_exec_sql_text(plan_handle) AS st

WHERE [text] LIKE N'%/* GetOnlineSearchResultsMonday %';

 

-- Remove the specific plan from the cache using the plan handle

DBCC FREEPROCCACHE (0x05000800F7BA926C40C15055070000000000000000000000);