SQL第六章(存储过程)

1、存储过程的优点

①允许模块化程序设计

②执行速度更快

③减少网络流通量

④提高系统安全性

2、存储过程的分类

①系统存储过程

②用户自定义存储过程

3、常用的系统存储过程

 

4、使用存储过程

①定义存储过程分语法

        created proc  存储过程名

         as

                 T- SQL语句

         go

 

 

②调用语法

      exec  过程名   【参数】

5、创建不带参数的存储过程

if exists(select*from sys.procedures where name='pr_stu_mark')
drop proc pr_stu_mark
go

create proc pr_stu_mark
as
    select StuInfo.stuid,stuname,stusex,subject,score
    from StuInfo,StuMarks
    where StuInfo.stuid=StuMarks.stuid

go

 

--查询存储过程
--exec dbo.存储过程名字
exec dbo.pr_stu_mark '李四'

 

6、创建带参数的存储过程

存储过程的参数分两种

    ①输入参数   用于想存储过程传入值,

    ②输出参数   用于在调用存储过程后,返回结果

if exists(select*from sys.procedures where name='pr_stu_mark')
drop proc pr_stu_mark
go

create proc pr_stu_mark(@name varchar(10)=null)
as
if @name is null
begin
    select StuInfo.stuid,stuname,stusex,subject,score
    from StuInfo,StuMarks
    where StuInfo.stuid=StuMarks.stuid
end
else
begin
    select StuInfo.stuid,stuname,stusex,subject,score
    from StuInfo,StuMarks
    where StuInfo.stuid=StuMarks.stuid and stuName=@name
end

go

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值