Reputation: 115
I guess,
When i use temporary table in Stored Procedure ,the stored procedure will be automatically recompiled.
Kindly give me the other possibilites.
Upvotes: 4
Views: 7532
Reputation: 19392
The other 2 answers here (by @KM. and @gbn) list reasons for SQL to "invalidate" the cached plan.
What I mean by "invalidate" is, something caused the existing plan to require a recompilation.
However, I believe the #1 recurring reason for recompilation is the cached plan no longer exists.
This could be due to:
Here is a great link on #3 Above (how clearing the cache may be done manually):
My takeaway from the link above was to search your jobs and stored procedures for anything containing:
I've worked in various databases and I've had the luck of seeing my stored procedure's cached plans last no more than 24 hours (usually a lot less), so by the next day, everything needs to be recompiled.
In my experience, caching works, but usually only for a few hours out of the work day, so never expect your plans to last beyond that.
Upvotes: 0
Reputation: 103579
Optimizing SQL Server Stored Procedures to Avoid Recompiles
Upvotes: 3
Reputation: 432180
It's all here: Execution Plan Caching and Reuse under the section "Recompiling Execution Plans"
Upvotes: 3