My SQL Server存储过程创建及调用_MySQL
bitsCN.com
My SQL Server存储过程创建及调用
存储过程优点:
① 执行速度快
② 模板化程序设计
③ 减少网络流量
④提供系统安全性
.什么是存储过程
存储过程(stored procdures)是Sql查询语句与控制流语句的预编译集合,并以特定的名称保存在数据库中。且分为自定义存储过程与系统存储过程
·系统存储过程
→系统存储过程命名以“sp_”开头和“xp_”开头。在master数据库中
→扩展存储过程:xp_cmdshell ,可以调用DOS命令
用法如下:
exec xp_cmdshell Dos命令 [no_output]
→execute 用来调用存储过程,也可缩写为exec
语法:
execute '存储过程名' '参数' --如果没有参数则省略参数
·用户自定义存储过程
语法:
create procedure 存储过程名
@参数1名 数据类型[ = 默认值][参数类型(输入/输出)]
...
@参数n名 数据类型[ = 默认值][参数类型(输入/输出)]
as
sql语句
...
go
*注意:参数类型分为输入与输出参数,默认为输入参数,使用output表示输出,创建存储过程最好以 proc 开头。
①创建不带参数的存储过程
例:
查询所有空闲的电脑信息
--判断存储过程是否存在
if exists(select * from sysobjects where[name]='proc_GetPc')
drop procedure proc_GetPc
go
--创建不带参数的存储过程
create procedure proc_GetPc
--没有参数
as
select pcId as '电脑编号',
'电脑使用状态'=case
when PcUse=0 then '空闲'
when PcUse=1 then '空闲'
PcNote as '备注'
from PcInfo where PcUse=0
go
--调用存储过程
execute proc_GetPc
②创建带输入参数的存储过程
语法:
create procedure 存储过程名
@参数1名 数据类型[= 默认值]
...
@参数N名 数据类型[= 默认值]
as
SQL语句
...
go
③创建带输出参数的存储过程
与C语言的返回值类似,执行存储过程后,一可以返回值。但与C语言只能返回一个值不同,存储过程可以返回一个或多个值。这就需要我们定义并接收输出(output)参数。
④return的使用
return 关键字终止存储过程的执行或返回数据。类似C语言函数中的return。
return 只能返回int 类型,output 返回任意类型。
·处理错误信息
SQL Server中使用raiserror返回用户自定义的错误信息。
语法:
RAISERROR(自定义的错误信息,错误的严重级别,错误的状态)
→自定义错误信息:表示输出的错误提示文本。
→错误的严重级别:表示用户自定义错误的严重级性级别。
→错误的状态:表示自定义错误的状态,值的范围在1-127。
.存储过程是数据库对象,可以使用 DROP PROCEDURE语句删除存储过程。
bitsCN.com
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



This article will introduce the solution to the problem that the globe symbol is displayed on the Win10 system network but cannot access the Internet. The article will provide detailed steps to help readers solve the problem of Win10 network showing that the earth cannot access the Internet. Method 1: Restart directly. First check whether the network cable is not plugged in properly and whether the broadband is in arrears. The router or optical modem may be stuck. In this case, you need to restart the router or optical modem. If there are no important things being done on the computer, you can restart the computer directly. Most minor problems can be quickly solved by restarting the computer. If it is determined that the broadband is not in arrears and the network is normal, that is another matter. Method 2: 1. Press the [Win] key, or click [Start Menu] in the lower left corner. In the menu item that opens, click the gear icon above the power button. This is [Settings].

1. Check the wifi password: Make sure the wifi password you entered is correct and pay attention to case sensitivity. 2. Confirm whether the wifi is working properly: Check whether the wifi router is running normally. You can connect other devices to the same router to determine whether the problem lies with the device. 3. Restart the device and router: Sometimes, there is a malfunction or network problem with the device or router, and restarting the device and router may solve the problem. 4. Check the device settings: Make sure the wireless function of the device is turned on and the wifi function is not disabled.

In daily life and work, we often need to share files and folders between different devices. Windows 11 system provides convenient built-in folder sharing functions, allowing us to easily and safely share the content we need with others within the same network while protecting the privacy of personal files. This feature makes file sharing simple and efficient without worrying about leaking private information. Through the folder sharing function of Windows 11 system, we can cooperate, communicate and collaborate more conveniently, improving work efficiency and life convenience. In order to successfully configure a shared folder, we first need to meet the following conditions: All devices (participating in sharing) are connected to the same network. Enable Network Discovery and configure sharing. Know the target device

Security challenges in Golang development: How to avoid being exploited for virus creation? With the wide application of Golang in the field of programming, more and more developers choose to use Golang to develop various types of applications. However, like other programming languages, there are security challenges in Golang development. In particular, Golang's power and flexibility also make it a potential virus creation tool. This article will delve into security issues in Golang development and provide some methods to avoid G

Douyin is one of the most popular short video platforms in China, attracting more than 500 million monthly active users, making Douyin a hot target for advertisers and content creators. Douyin’s high traffic has the following significant advantages, attracting many interested friends, so you might as well take a look. 1. What are the benefits of having high Douyin traffic? The high traffic of Douyin means that the advertising coverage is broad. As the number of users increases, advertisers can reach more potential consumers on Douyin. This is a huge opportunity for branding to expose your product or service to a larger audience, increasing awareness and exposure. Increasing Douyin traffic can help increase sales. Through proper promotion and publicity on Douyin, companies can attract more users to learn about and purchase their products. Douyin with

Memory management in Java involves automatic memory management, using garbage collection and reference counting to allocate, use and reclaim memory. Effective memory management is crucial for security because it prevents buffer overflows, wild pointers, and memory leaks, thereby improving the safety of your program. For example, by properly releasing objects that are no longer needed, you can avoid memory leaks, thereby improving program performance and preventing crashes.

Editor's note: In 2023, the Dragon Lizard Community officially established the System Operation and Maintenance Alliance, which consists of the Academy of Information and Communications Technology, Alibaba Cloud, ZTE, Fudan University, Tsinghua University, Zhejiang University, Yunguan Qiuhao, Chengyun Digital, Yunshan Network, and Inspur Information, China Unicom Software and China Unicom Software Institute and other 12 units co-sponsored the initiative. This article is reproduced from Yun Guan Qiu Hao and introduces Kindling-OriginX, a member of the System Operation and Maintenance Alliance, to automatically generate interpretable fault root cause reports by combining DeepFlow's complete network data capabilities. DeepFlow is an open source project that leverages eBPF technology to provide high observability for complex cloud infrastructure and cloud native applications. Through eBPF technology, DeepFlow collects fine link tracking data, network

The services provided in the China Mobile app software are very considerate and support all mobile network users to download, install and use. You can log in online by entering your mobile phone number, check the data usage online at any time, and enjoy more stable network services. Open the software and you can operate it. Whether it is the balance of the phone bill or the activation and unsubscription of other value-added services, you can check it online. The speed is very fast. The 5g network is upgraded for free, and the speed during the Internet process is faster and more stable. You can also set the network usage values of different network cards, and you can freely switch the order. You don’t have to worry about insufficient traffic. Many mobile services can be processed online. Now the editor will provide detailed information online for China Mobile users to set traffic priority. Use a sequential approach. 1. Find the settings app on your phone
