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 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 Tools

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

The Xiaomi Mi 15 series is expected to be officially released in October, and its full series codenames have been exposed in the foreign media MiCode code base. Among them, the flagship Xiaomi Mi 15 Ultra is codenamed "Xuanyuan" (meaning "Xuanyuan"). This name comes from the Yellow Emperor in Chinese mythology, which symbolizes nobility. Xiaomi 15 is codenamed "Dada", while Xiaomi 15Pro is named "Haotian" (meaning "Haotian"). The internal code name of Xiaomi Mi 15S Pro is "dijun", which alludes to Emperor Jun, the creator god of "The Classic of Mountains and Seas". Xiaomi 15Ultra series covers

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

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

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

1. The SUM function is used to sum the numbers in a column or a group of cells, for example: =SUM(A1:J10). 2. The AVERAGE function is used to calculate the average of the numbers in a column or a group of cells, for example: =AVERAGE(A1:A10). 3. COUNT function, used to count the number of numbers or text in a column or a group of cells, for example: =COUNT(A1:A10) 4. IF function, used to make logical judgments based on specified conditions and return the corresponding result.

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

Since the Huawei Mate60 series went on sale last year, I personally have been using the Mate60Pro as my main phone. In nearly a year, Huawei Mate60Pro has undergone multiple OTA upgrades, and the overall experience has been significantly improved, giving people a feeling of being constantly new. For example, recently, the Huawei Mate60 series has once again received a major upgrade in imaging capabilities. The first is the new AI elimination function, which can intelligently eliminate passers-by and debris and automatically fill in the blank areas; secondly, the color accuracy and telephoto clarity of the main camera have been significantly upgraded. Considering that it is the back-to-school season, Huawei Mate60 series has also launched an autumn promotion: you can enjoy a discount of up to 800 yuan when purchasing the phone, and the starting price is as low as 4,999 yuan. Commonly used and often new products with great value

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

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

How to handle database connection errors in PHP How to handle database connection errors in PHP Jun 05, 2024 pm 02:16 PM

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

How to connect to remote database using Golang? How to connect to remote database using Golang? Jun 01, 2024 pm 08:31 PM

Through the Go standard library database/sql package, you can connect to remote databases such as MySQL, PostgreSQL or SQLite: create a connection string containing database connection information. Use the sql.Open() function to open a database connection. Perform database operations such as SQL queries and insert operations. Use defer to close the database connection to release resources.

How to use database callback functions in Golang? How to use database callback functions in Golang? Jun 03, 2024 pm 02:20 PM

Using the database callback function in Golang can achieve: executing custom code after the specified database operation is completed. Add custom behavior through separate functions without writing additional code. Callback functions are available for insert, update, delete, and query operations. You must use the sql.Exec, sql.QueryRow, or sql.Query function to use the callback function.

See all articles