Pages

Saturday, September 27, 2008

Recompile in SQL Server

In next couple of posts i will explain about some very usefull stored procedures in SQL Server.

SP_RECOMPILE: SP_RECOMPILE

The sp_recompile stored procedure is used to recompile certain database objects. When you create a database object for the first time, the database object is compiled and a query plan is generated if all the dependencies are met. If you change the data in database objects, the stored procedures and triggers should be recompiled because the query plans generated for the database objects are no longer valid and new query plans should be generated.


The below example causes stored procedures that are using EMP table to be recompiled the next time they are run.

USE Pubs;
GO
EXEC sp_recompile N'HR.EMP'
GO

No comments: