数据库系列之T
什么是存储过程 存储过程是保存在数据库的函数,可以被应用程序或其它存储过程调用。 存储过程有什么用 用于实现业务逻辑(特别是需要事务的业务)。 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)

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



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

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

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.

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

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())

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.

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.

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.
