DBCC FREEPROCCACHE

Remove all elements from the plan cache, removes a specific plan from the plan cache by specifying a plan handle or SQL handle, or removes all cache entries associated with a specified resource pool.

Syntax
      DBCC FREEPROCCACHE [ ( { plan_handle | sql_handle | pool_name } ) ] [ WITH NO_INFOMSGS ]

Key:
    plan_handle uniquely identifies a query plan for a batch that has executed
               and whose plan resides in the plan cache. 

    sql_handle is the SQL handle of the batch to be cleared. 

    pool_name is the name of a Resource Governor resource pool. 

    NO_INFOMSGS  - Suppress all information messages.

MARK_IN_USE_FOR_REMOVAL will not prevent new entries being created in the cache.
Requires ALTER SERVER STATE permission on the server.

Examples

Clear all plans from the plan cache:

DBCC FREEPROCCACHE WITH NO_INFOMSGS;

Clear all cache entries associated with a resource pool:

SELECT * FROM sys.dm_resource_governor_resource_pools;
GO
DBCC FREEPROCCACHE ('default');
GO

Clear a query plan from the plan cache:

USE AdventureWorks2022;
GO
SELECT * FROM person.address;
GO
SELECT plan_handle, st.text
FROM sys.dm_exec_cached_plans
CROSS APPLY sys.dm_exec_sql_text(plan_handle) AS st
WHERE text LIKE N'SELECT * FROM person.address%';
GO

plan_handle                                         text
--------------------------------------------------  -----------------------------
0x060006001ECA270EC0215D05000000000000000000000000  SELECT * FROM person.address;
  
(1 row(s) affected)

-- Remove the specific plan from the cache.
DBCC FREEPROCCACHE (0x060006001ECA270EC0215D05000000000000000000000000);
GO

“It's hard to be funny when you have to be clean” ~ Mae West

Related commands

DBCC FREESESSIONCACHE - Flush the distributed query connection cache.
DBCC FREESYSTEMCACHE - Release all unused cache entries from all caches.


 
Copyright © 1999-2026 SS64.com
Some rights reserved