Ask Learn
Preview
Please sign in to use this experience.
Sign inThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Causes stored procedures and triggers to be recompiled the next time they are run.
Transact-SQL Syntax Conventions
sp_recompile [ @objname = ] 'object'
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.
Note
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
CREATE PROCEDURE (Transact-SQL)
CREATE TRIGGER (Transact-SQL)
System Stored Procedures (Transact-SQL)
Please sign in to use this experience.
Sign in