How to execute a stored procedure when starting SQL SERVER?
Create the stored procedure in the master database, and then find the stored procedure in the Enterprise Manager--right-click--Properties--check "Execute whenever sql server starts".
--Or after creating the stored procedure in the master, set the execution statement to automatically start
use master
exec sp_procoption 'stored procedure name','startup',' on'
------------------------------------------------ ------------------
Automatically execute stored procedures
SQL Server can automatically execute one or more a stored procedure. These stored procedures must be created by a system administrator and executed as background processes under the sysadmin fixed server role. These procedures cannot have any input parameters.
There is no limit on the number of startup processes, but please note that each startup process will occupy a connection when executed. If multiple procedures must be executed at startup, but do not need to be executed in parallel, you can designate one process as the startup procedure and have it call other procedures. This only takes up one connection.
After the last database is restored at startup, the stored procedure begins to be executed. To skip execution of these stored procedures, specify the startup parameter as trace flag 4022. If you start SQL Server with minimal configuration (using the -f flag), the startup stored procedure will also not execute. For more information, see Trace Tags.
To create a startup stored procedure, you must be logged in as a member of the sysadmin fixed server role and create the stored procedure in the master database.
Use sp_procoption to:
Specify an existing stored procedure as the startup procedure.
Prevents the process from executing when SQL Server starts.
The above is the detailed content of Introduction to SQL SERVER automatically executing stored procedures. For more information, please follow other related articles on the PHP Chinese website!