sp_recompile System Stored Procedure

Causes each stored procedure and trigger that uses the specified table to be recompiled the next time the stored procedure and triggers are run.

Syntax

sp_recompile tabname

where

tabname
Specifies a table in the current database.

Remarks

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

The sp_recompile system procedure looks for a table in the current database only. It cannot be used on system tables.

Example

This example causes each trigger and stored procedure that uses the titles table to be recompiled the next time it is run.

sp_recompile titles

Permission

Execute permission defaults to the public group.

Table Used

sysobjects