s

MS SQL Server stored procedure slowing down over time and then speeding up again after opening and saving edit button Edit

author
Murugan Andezuthu Dharmaratnam | calendar 20 March 2024 | 502

MS SQL Server stored procedure slowing down over time and then speeding up again after opening and saving.

Solution

Recompile the Stored Procedure: Forcing a stored procedure to recompile each time it is executed can ensure that SQL Server creates an optimal execution plan for the current parameter values. This can be done using the RECOMPILE query hint or by calling sp_recompile to mark the stored procedure for recompilation.

-- Using RECOMPILE in the query
SELECT * FROM MyTable WHERE Column = @Parameter
OPTION (RECOMPILE);

-- Or using sp_recompile to mark the stored procedure for recompilation
EXEC sp_recompile 'MyProcedure';