Home > Database > Mysql Tutorial > Introduction to SQL SERVER automatically executing stored procedures

Introduction to SQL SERVER automatically executing stored procedures

伊谢尔伦
Release: 2017-06-16 11:15:10
Original
2068 people have browsed it

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template