View Full Version : مشكل در نرم افزار sql
zkazemi
دوشنبه 24 اسفند 1388, 14:56 عصر
سلام
می خواستم بدونم گزینه RECOMPILE در هنگام ایجاد یک پروسیجر دقیقا برای چه کاری ؟ می دونم که هنگام ایجاد یک پروسیجر می توان به طور مستقیم اون رو کامپایل کرد تا از این کد های کامپایل ایجاد شده در هنگام EXEC کردن استفاده بشه. اما می خوام بدونم که دلیل استفاده از این OPTION هنگام EXEC کردن یک پروسیجر دقیقا چیه ؟ یعنی مکانیسم این گزینه در هنگام اجرای پروسیجر چیه؟
supporter
دوشنبه 24 اسفند 1388, 15:41 عصر
از Help خود SqlServer :
Recompiling a Stored Procedure
As a database is changed by such actions as adding indexes or changing data in indexed columns, the original query plans used to access its tables should be optimized again by recompiling them. This optimization happens automatically the first time a stored procedure is run after Microsoft® SQL Server™ 2000 is restarted. It also occurs if an underlying table used by the stored procedure changes. But if a new index is added from which the stored procedure might benefit, optimization does not automatically happen (until the next time the stored procedure is run after SQL Server is restarted).
SQL Server provides three ways to recompile a stored procedure:
The sp_recompile system stored procedure forces a recompile of a stored procedure the next time it is run.
Creating a stored procedure that specifies the WITH RECOMPILE option in its definition indicates that SQL Server does not cache a plan for this stored procedure; the stored procedure is recompiled each time it is executed. Use the WITH RECOMPILE option when stored procedures take parameters whose values differ widely between executions of the stored procedure, resulting in different execution plans to be created each time. Use of this option is uncommon, and causes the stored procedure to execute more slowly because the stored procedure must be recompiled each time it is executed.
You can force the stored procedure to be recompiled by specifying the WITH RECOMPILE option when you execute the stored procedure. Use this option only if the parameter you are supplying is atypical or if the data has significantly changed since the stored procedure was created.
Note If an object referenced by a stored procedure is deleted or renamed, an error is returned when the stored procedure is executed. If, however, an object referenced in a stored procedure is replaced with an object of the same name, the stored procedure executes without having to be recompiled.
vBulletin® v4.2.5, Copyright ©2000-1404, Jelsoft Enterprises Ltd.