Sql-server – Prevent Caching in SQL Server

cachingsql serversql-server-2005

Having looked around the net using Uncle Google, I cannot find an answer to this question:

What is the best way to monitor the performance and responsiveness of production servers running IIS and MS SQL Server 2005?

I'm currently using Pingdom and would like it to point to a URL which basically mimics a 'real world query' but for obvious reasons do not want the query to run from cache. The URL will be called every 5 minutes.

I cannot clear out the cache, buffers, etc since this would impact negatively on the production server. I have tried using a random generated number within the SELECT statement in order to generate unique queries, but the cached query is still used.

Is there any way to simulate the NO_CACHE in MySQL?

Regards

Best Answer

To clear the SQL buffer and plan cache:

DBCC DROPCLEANBUFFERS
GO
DBCC FREEPROCCACHE
GO

A little info about these commands from MSDN:

Use DROPCLEANBUFFERS to test queries with a cold buffer cache without shutting down and restarting the server. (source)

Use DBCC FREEPROCCACHE to clear the plan cache carefully. Freeing the plan cache causes, for example, a stored procedure to be recompiled instead of reused from the cache. (source)