views:

767

answers:

5

I've looked all over for this command....what's the command to reset the SQL Server's execution plan?

+2  A: 

For stored procedures, you use the WITH RECOMPILE option.

Joel Coehoorn
+1 AHA !! Now things begin to make sense :-) You're better at deciphering unclear user messages, I must see...
marc_s
Please notes that this method will recompile the given stored procedure each and every time it is executed, so if you wish to just force a one off recompile then use the system stored procedure sp_recompile.
John Sansom
A: 

sp_recompile will dump the existing query plan and recompile the procedure. Or you can restart SQL and that will clear the entire execution plan cache.

WITH RECOMPILE is going to generate a new plan EVERY time you execute it.

ElHombre
A small but important distinction, executing sp_recompile will not recompile a given stored procedure but will instead mark it for recompilation the next time it is executed.
John Sansom
+2  A: 

If you want to reset QEP for a stored procedure, you shall use sp_recompile

Rubens Farias
A: 

It's not entirely clear from your question what you're after. But in addition to the other suggestions, DBCC FREEPROCCACHE clears all cached execution plans.

RoadWarrior
+1  A: 

For clarity..........

Executing sp_recompile will "mark" the given stored procedure for recompilation, which will occur the next time it is executed.

Using the WITH RECOMPILE option will result in a new execution plan being generated each time the given stored procedure is executed.

To clear the entire procedure cache execute

DBCC FREEPROCCACHE
John Sansom
That's what I was looking for, clearing the cache! Thanks!
Brandon