While looking for a detailed explanation of cache-store flush messages in the SQL Server ERRORLOG, I came across this page: http://blogs.msdn.com/b/sqlprogrammability/archive/2007/01/17/10-0-plan-cache-flush.aspx, which refers to dropping a database causing the procedure cache to be flushed.
As someone that occasionally creates separate databases to hold temporary data, or a subset of an entire database, I did some investigations.
SELECT * FROM sys.dm_os_memory_cache_counters WHERE name in ('Object Plans', 'SQL Plans', 'Bound Trees') SELECT * FROM sys.dm_exec_cached_plans
This code simply reports on the state of the procedure cache at the server level.
CREATE DATABASE TestDB GO DROP DATABASE TestDB GO SELECT * FROM sys.dm_os_memory_cache_counters WHERE name in ('Object Plans', 'SQL Plans', 'Bound Trees') SELECT * FROM sys.dm_exec_cached_plans
We create a database, drop it, and then execute the queries from Script 1.
Conveniently, I have two development instances (2005 and 2008) with detailed plan caches that I have no problems with potentially flushing. In SQL Server 2005, we get the following:
Before (Script 1):
After (Script 2):
As (unfortunately) expected, the procedure cache is gone. Now let’s try SQL Server 2008:
No change! Fantastic! The obvious conclusion is that you can drop or detach databases as much as you like in SQL Server 2008, but you may want to be aware of the potential effect you have on the server when using 2005.