Hi Friends,
Performance tuning/ Query tuning in SQL Server is a combo of art and science. During the query tuning, we sometimes need to clear the cache for actual benchmarking purposes. Here is the code to do that:
To clear data from cache globally:
DBCC DROPCLEANBUFFERS;
To clear execution plans from cache globally:
DBCC FREEPROCCACHE;
To clear execution plans of a particular database:
DBCC FLUSHPROCINDB(<db_id>);
The above command is undocumented.
Note: Be careful of using the above commands in your productuon enviornments. It may impact performence negatively to a good extent. We use it more to analyze performance in test enviornments.