search
Homephp教程php手册SQL Server启动服务器时运行的存储过程

当 SQL Server 启动时 ,我很想运行一个存储过程。有没有一种方法可以在每次 SQL Server 服务启动时都会自动执行这个存储过程呢 ? SQL Server 提供了系统存储过程 sp_procoption ,这个存储过程可以用于当 SQL Server 服务启动时指派一个或者多个 存储过程自

SQL Server启动时,我很想运行一个存储过程。有没有一种方法可以在每次SQL Server服务启动时都会自动执行这个存储过程呢?

 

SQL Server提供了系统存储过程sp_procoption,这个存储过程可以用于当SQL Server服务启动时指派一个或者多个存储过程自动执行。这是一个很不错的选择,它可以用于多种多样的用途。比如,你可能在你的数据库中有开销很大的查询,这个查询在首次执行时会花费一些时间。通过使用sp_procoption,你可以在服务器启动时运行这个查询以此来预先编译执行计划,由此,你的某个用户就不会成为第一个运行这个特殊查询的不幸的人。我曾经用这个功能建立了一个我自己写的概要分析器服务器端跟踪的自动执行功能,这个跟踪功能成为服务器启动时被设置成自动执行的存储过程的一部分。


  sp_procoption Parameters 
  
exec sp_procoption @ProcName = ['stored procedure name'], 
  
@OptionName = 'STARTUP', 
  @OptionValue = [on|off]


  以下是sp_procoption存储过程参数的解释:

1.       参数@ProcName的意思是明显的,它是被标记成自动执行的过程的名称。

2.       参数@OptionName是可选用项,唯一有效的选项是STARTUP

3.       参数@OptionValue切换自动执行的开与关。

  使用有特定限制的sp_procoption

l         你必须以系统管理员的身份登录服务器并使用sp_procoption

l         你只能指派标准存储过程、扩展存储过程或者CLR存储过程来启动。

l         存储过程必须在主从数据库上。

l         存储过程不能要求任何输入参数或者返回任何输出参数。

例如:

CREATE PROCEDURE dbo.chen

AS

       INSERT INTO pubs.dbo.jobs(job_desc,min_lvl,max_lvl) SELECT 'chenjianping',45,56

 

GO

 

EXEC sp_procoption 'chen','STARTUP','on'

GO

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment