什么是存储过程
存储过程
存储过程(Stored Procedure)是一组为了完成特定功能的SQL语句集,经编译后存储在数据库中。用户通过指定存储过程的名字并给出参数(如果该存储过程带有参数)来执行它。存储过程是数据库中的一个重要对象,任何一个设计良好的数据库应用程序都应该用到存储过程。总的来说,存储过程具有以下一些优点:
◆存储过程允许标准组件式编程
◆存储过程能够实现较快的执行速度
◆存储过程能够减少网络流量
◆存储过程可被作为一种安全机制来充分利用
--9.修改上例,返回未通过考试的学员人数。
alter procedure p2
(
@nopassNums int output,
-- 参数设置默认值
@written int=60,
@lab int=60
)
as
select avg(writtenExam+labExam) from exam
select * from exam
where writtenExam<@written or labExam<@lab
select @nopassNums=count(*) from exam
where writtenExam<@written or labExam<@lab
--调用
declare @num int
exec p2 @num output,70,70
select @num
select * from exam
立志欲坚不欲锐,成功在久不在速。