sp_procoption (Transact-SQL)sp_procoption (Transact-SQL)

适用对象: 是SQL Server 否Azure SQL 数据库 否Azure Synapse Analytics (SQL DW) 否并行数据仓库 APPLIES TO: yesSQL Server noAzure SQL Database noAzure Synapse Analytics (SQL DW) noParallel Data Warehouse

设置或清除自动执行的存储过程。Sets or clears a stored procedure for automatic execution. 设置为自动执行运行每次的实例的存储的过程SQL ServerSQL Server已启动。A stored procedure that is set to automatic execution runs every time an instance of SQL ServerSQL Server is started.

主题链接图标 TRANSACT-SQL 语法约定Topic link icon Transact-SQL Syntax Conventions


sp_procoption [ @ProcName = ] 'procedure'   
    , [ @OptionName = ] 'option'   
    , [ @OptionValue = ] 'value'   


[ @ProcName = ] 'procedure' 是要为其设置选项的名称。[ @ProcName = ] 'procedure' Is the name of the procedure for which to set an option. 过程nvarchar(776) ,无默认值。procedure is nvarchar(776), with no default.

[ @OptionName = ] 'option' 是要设置的名称。[ @OptionName = ] 'option' Is the name of the option to set. 唯一的值为选项启动The only value for option is startup.

[ @OptionValue = ] 'value' 是否要选项设置为 on ( ,则返回 true) 或禁用 (false或者关闭)。[ @OptionValue = ] 'value' Is whether to set the option on (true or on) or off (false or off). varchar(12) ,无默认值。value is varchar(12), with no default.

返回代码值Return Code Values

0(成功)或错误号(失败)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.


要求具有 sysadmin 固定服务器角色的成员身份。Requires membership in the sysadmin fixed server role.


下面的示例设置过程自动执行。The following example sets a procedure for automatic execution.

EXEC sp_procoption @ProcName = N'<procedure name>'   
    , @OptionName = 'startup'   
    , @OptionValue = 'on';   

下面的示例阻止过程自动执行。The following example stops a procedure from executing automatically.

EXEC sp_procoption @ProcName = N'<procedure name>'      
    , @OptionName = 'startup'
    , @OptionValue = 'off';   

请参阅See Also

执行存储过程Execute a Stored Procedure