Table of Contents
什么是存储过程
存储过程有什么用
 
常用的系统存储过程
调用系统存储过程
扩展存储过程
用户自定义存储过程
1 不带参数的存储过程
2 带参数的存储过程
3 带输出参数的存储过程
Home Database Mysql Tutorial 数据库系列之T

数据库系列之T

Jun 07, 2016 pm 03:00 PM
What function Can storage exist database series process

什么是存储过程 存储过程是保存在数据库的函数,可以被应用程序或其它存储过程调用。 存储过程有什么用 用于实现业务逻辑(特别是需要事务的业务)。 1 优点 减少网络通信量 执行速度更快 更强的适应性(有时候发布系统无需更新客户端) 分布式工作 减少客户

什么是存储过程


存储过程是保存在数据库的函数,可以被应用程序或其它存储过程调用。

存储过程有什么用


用于实现业务逻辑(特别是需要事务的业务)。
1 优点
减少网络通信量
执行速度更快
更强的适应性(有时候发布系统无需更新客户端)
分布式工作
减少客户端的负荷
2 缺点
增加服务器的负荷

 

常用的系统存储过程

系统存储过程    说明
sp_help    用于查看对象信息
sp_helpdb    用于查询数据库的信息
sp_helpconstraint    查看某个表的约束
sp_helpindex    查看某个表的索引
sp_databases    用于显示所有数据库的信息,如数据库名和数据大小。
sp_renamedb    更改数据库的名称
Sp_rename    用于在当前数据库更改用户创建的对象名称,如数据表、字段、索引等
sp_tables    返回当前数据库中数据表和视图
sp_columns    返回某个数据表或视图的列信息
sp_password    添加或修改登录帐户的密码

调用系统存储过程

exec sp_databases  --列出当前系统中的所有数据库
use booksmanager
go
exec sp_tables  --列出数据库booksmanager中所有数据表和视图
exec sp_columns books --列出图书表的列信息
exec sp_help books --查看图书表的所有信息
exec sp_helpconstraint books --查看图书表的约束
exec sp_helpindex books --查看图书表的索引

扩展存储过程

扩展存储过程(Extended  stored  procedured)是对动态链接库(DLL)函数的调用。
扩展存储过程通常是以“XP_”为前缀。

用户自定义存储过程

1 不带参数的存储过程

(1)语法
CREATE  PROCEDURE  存储过程名
AS
  ………
  ………
  ………
建议:自定义存储过程的名称最好以USP_开头
(2)调用带输入参数的存储过程
EXEC  存储过程名

2 带参数的存储过程

(1)语法
CREATE  PROCEDURE  存储过程名
    @参数1  数据类型 [=默认值],
     ……
    @参数n  数据类型 [=默认值]
AS
  ………
  ………
  ………
(2)调用带输入参数的存储过程
方式一:
exec usp_score_byparam 'SQL Server基础编程',70
方式二:
exec usp_score_byparam @coursename='SQL Server基础编程' ,@pass=70

3 带输出参数的存储过程

(1)语法
CREATE  PROCEDURE  存储过程名
    @参数1  数据类型 [=默认值],
     ……
    @参数n  数据类型 OUTPUT
AS
  ………
  ………
  ………
(2)调用带输出参数的存储过程
declare @result  int
exec usp_ADD 20,30,@result output
print '运算结果:'+str(@result,5)

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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Xiaomi 15 series full codenames revealed: Dada, Haotian, Xuanyuan Xiaomi 15 series full codenames revealed: Dada, Haotian, Xuanyuan Aug 22, 2024 pm 06:47 PM

Xiaomi 15 series full codenames revealed: Dada, Haotian, Xuanyuan

Complete collection of excel function formulas Complete collection of excel function formulas May 07, 2024 pm 12:04 PM

Complete collection of excel function formulas

The best time to buy Huawei Mate 60 series, new AI elimination + image upgrade, and enjoy autumn promotions The best time to buy Huawei Mate 60 series, new AI elimination + image upgrade, and enjoy autumn promotions Aug 29, 2024 pm 03:33 PM

The best time to buy Huawei Mate 60 series, new AI elimination + image upgrade, and enjoy autumn promotions

Detailed tutorial on establishing a database connection using MySQLi in PHP Detailed tutorial on establishing a database connection using MySQLi in PHP Jun 04, 2024 pm 01:42 PM

Detailed tutorial on establishing a database connection using MySQLi in PHP

iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos Jul 18, 2024 am 05:48 AM

iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos

C++ Function Exception Advanced: Customized Error Handling C++ Function Exception Advanced: Customized Error Handling May 01, 2024 pm 06:39 PM

C++ Function Exception Advanced: Customized Error Handling

How does Go WebSocket integrate with databases? How does Go WebSocket integrate with databases? Jun 05, 2024 pm 03:18 PM

How does Go WebSocket integrate with databases?

Things to note when Golang functions receive map parameters Things to note when Golang functions receive map parameters Jun 04, 2024 am 10:31 AM

Things to note when Golang functions receive map parameters

See all articles