The stored procedure is automatically executed when SQL Server is started.

Source: Internet
Author: User
The stored procedure is automatically executed when SQL Server is started.
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 the stored procedure and choose Properties. Select "execute whenever SQL Server is started ".

-- Or after the stored procedure is created in the master, the execution statement is set to automatic start.

Use master

Exec sp_procoption 'stored procedure name', 'startup', 'on'
---------------------------------------------------------------

Automatic Execution of Stored Procedures

When SQL Server is started, one or more stored procedures can be automatically executed. These stored procedures must be created by the system administrator and executed as background procedures under the SysAdmin fixed server role. These processes cannot have any input parameters.

There is no limit on the number of startup processes, but note that each Startup Process occupies a connection during execution. If multiple processes must be executed at startup without parallel execution, you can specify a process as the startup process to call other processes. In this way, only one connection is occupied.

After the last database is restored at startup, the stored procedure starts. To skip the execution of these stored procedures, set the startup parameter to trace tag 4022. If SQL Server is started with the lowest configuration (with the-F flag), the stored procedure will not be started. For more information, see trace tag.

To create a stored procedure, you must log on as a member of the SysAdmin fixed server role and create a stored procedure in the master database.

You can use sp_procoption:

Specify an existing stored procedure as a startup process.

The blocking process is executed when SQL Server is started.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.