Click to Rate and Give Feedback
MSDN
MSDN Library
SQL Server
SQL Server 2008
Database Engine
Technical Reference
 sp_recompile (Transact-SQL)

  Switch on low bandwidth view
Community Content
In this section
Statistics Annotations (0)
Other versions are also available for the following:
SQL Server 2008 Books Online (June 2009)
sp_recompile (Transact-SQL)

Causes stored procedures and triggers to be recompiled the next time they are run.

Topic link icon Transact-SQL Syntax Conventions

sp_recompile [ @objname = ] 'object'
[ @objname = ] 'object'

Is the qualified or unqualified name of a stored procedure, trigger, table, or view in the current database. object is nvarchar(776), with no default. If object is the name of a stored procedure or trigger, the stored procedure or trigger will be recompiled the next time that it is run. If object is the name of a table or view, all the stored procedures that reference the table or view will be recompiled the next time they are run.

0 (success) or a nonzero number (failure)

sp_recompile looks for an object in the current database only.

The queries used by stored procedures and triggers are optimized only when they are compiled. As indexes or other changes that affect statistics are made to the database, compiled stored procedures and triggers may lose efficiency. By recompiling stored procedures and triggers that act on a table, you can reoptimize the queries.

ms181647.note(en-us,SQL.100).gifNote:
SQL Server automatically recompiles stored procedures and triggers when it is advantageous to do this.

Requires ALTER permission on the specified object.

The following example causes stored procedures that act on the Customer table to be recompiled the next time they are run.

USE AdventureWorks;
GO
EXEC sp_recompile N'Sales.Customer';
GO
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker