Thursday, February 26, 2015

How to force a query to recompile every time in SQL server.

If you want to clear execution plan and cache, you could use the below commands

DBCC FreeProcCache
DBCC DropCleanbuffers


More details here
https://msdn.microsoft.com/en-us/library/ms174283.aspx

If you want to force query compilation each time, just add the below to the end of the query

OPTION (RECOMPILE)