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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

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.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.