I am using MS SQL Server 2012. I am trying to see the optimization in the server so I can't just clear everything.
This link didn't work for me. (or this example)
Any suggestions how I can select the query and clear the cache afterwards?
(or prevent it from caching would be better)
EDIT:
Most desired outcome is testing the select query like it's running for the very first time.
You can query
sys.dm_exec_connectionsto get a handle to last executed query for a given connection, and then evict that plan withDBCC FREEPROCCACHE. Make sure you do this on another connection.Alternatively, use
WITH RECOMPILEorOPTION(RECOMPILE)to not cache the plan at all:http://blogs.msdn.com/b/sqlmeditation/archive/2013/01/01/is-it-really-quot-recompile-quot-or-a-quot-private-temporary-compile-quot.aspx