怎么创建存储过程
Jun 07, 2016 pm 05:46 PM这篇文章主要是讲使用存储过程创建表和怎么创建存储过程以及如何创建存储过程为主题的文章
表book的内容如下
编号 书名 价格
001 C语言入门 $30
002 PowerBuilder报表开发 $52
实例1:查询表Book的内容的存储过程
以下为引用的内容:
create proc query_book
as
select * from book
go
exec query_book
实例2:加入一笔记录到表book,并查询此表中所有书籍的总金额
以下为引用的内容:
Create proc insert_book
@param1 char(10),@param2 varchar(20),@param3 money,@param4 money output
with encryption ---------加密
as
insert book(编号,书名,价格) Values(@param1,@param2,@param3)
select @param4=sum(价格) from book
go
执行例子:
以下为引用的内容:
declare @total_price money
exec insert_book '003','Delphi 控件开发指南',$100,@total_price
print '总金额为'+convert(varchar,@total_price)
go
存储过程的3种传回值:
1.以Return传回整数
2.以output格式传回参数
3.Recordset
传回值的区别:
output和return都可在批次程式中用变量接收,而recordset则传回到执行批次的客户端中
实例3:设有两个表为Product,Order,其表内容如下:
以下为引用的内容:
Product
产品编号 产品名称 客户订数
001 钢笔 30
002 毛笔 50
003 铅笔 100
order
产品编号 客户名 客户订金
001 南山区 $30
002 罗湖区 $50
003 宝安区 $4
请实现按编号为连接条件,将两个表连接成一个临时表,该表只含编号.产品名.客户名.订金.总金额,
总金额=订金*订数,临时表放在存储过程中
代码如下:
以下为引用的内容:
Create proc temp_sale
as
select a.产品编号,a.产品名称,b.客户名,b.客户订金,a.客户订数* b.客户订金 as总金额
into #temptable from Product a inner join order b on a.产品编号=b.产品编号
if @@error=0
print 'Good'
else
print 'Fail'
go

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

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

Solution: Your organization requires you to change your PIN

How to adjust window border settings on Windows 11: Change color and size

How to change title bar color on Windows 11?

How to enable or disable taskbar thumbnail previews on Windows 11

OOBELANGUAGE Error Problems in Windows 11/10 Repair

10 Ways to Adjust Brightness on Windows 11

How to turn off private browsing authentication for iPhone in Safari?
