Causes stored procedures and triggers to be recompiled the next time they are run. It does this by dropping the existing plan from the procedure cache forcing a new plan to be created the next time that the procedure or trigger is run. In a SQL Server Profiler collection, the event SP:CacheInsert is logged instead of the event SP:Recompile.
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.
SQL Server automatically recompiles stored procedures and triggers when it is advantageous to do this.
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