Andrea Azzola

Technology, Personal Development and Financial Independence

Clean Up Stored Procedures Cache with SQL Server

Posted on [Permalink]

When deploying a stored procedure, a clean up the db's cache might go a long way in order to apply changes immediately. Have a look to the following code:

-- Cleans up db's cache
DECLARE @dbID INTEGER
SET @dbID = (SELECT dbid FROM master.dbo.sysdatabases WHERE name = 'DBNameHere')
DBCC FLUSHPROCINDB (@dbID)

The DBCC FLUSHPROCINDB command allows for specifing a particular database id, and then clears all the plans from it.

Categories: SQL Server