Applies To: SQL Server 2014, SQL Server 2016 Preview
Sets or clears a stored procedure for automatic execution. A stored procedure that is set to automatic execution runs every time an instance of SQL Server is started.
Applies to: SQL Server (SQL Server 2008 through current version).
- [ @ProcName = ] 'procedure'
Is the name of the procedure for which to set an option. procedure is nvarchar(776), with no default.
- [ @OptionName = ] 'option'
Is the name of the option to set. The only value for option is startup.
- [ @OptionValue = ] 'value'
Is whether to set the option on (true or on) or off (false or off). value is varchar(12), with no default.
0 (success) or error number (failure)
Startup procedures must be in the master database and cannot contain INPUT or OUTPUT parameters. Execution of the stored procedures starts when all databases are recovered and the "Recovery is completed" message is logged at startup.
Requires membership in the sysadmin fixed server role.
The following example sets a procedure for automatic execution.
EXEC sp_procoption @ProcName = '<procedure name>' , @OptionName = ] 'startup' , @OptionValue = 'on';
The following example stops a procedure from executing automatically.
EXEC sp_procoption @ProcName = '<procedure name>' , @OptionValue = 'off';