1存储过程是一组预编译的SQL语句,存储过程可以包含数据操纵语句、逻辑控制语句个调用函数 2存储过程可以加快查询的执行速度,提高访问数据的速度,帮助实现模块化编程,保持一致性和提高安全性 3存储过程分为2中系统存储过程用户自定义存储过程用creat proc 语句创建用户自定义存储过程用exec语句调用存储过程存储过程的参数分为输入参数和输出参数,输入参数向存储过程中传入值,输出参数从存储过程中返回值,后面跟随“out put”关键字. Raiserror语句用来向用户报告错误创建存储过程
- if exists (select * from sysobjects where name=’proc_stu’)
- drop proc proc_stu
- go
- creat proc proc_stu
- @sum int output,@writtenpass int=60,@labpass=60
- As select stuName,stuInfo.stuNo,writtenExam,labExam from stuInfo inner join stuMarks on stuInfo.stuNo=stuMarks.stuNo where writtenExam<@writtenExam or labExam<@labpass
- Select @sum=count(stuNo) from stuMarks where where writtenExam<@writtenExam or labExam<@labpass
- //调用存储过程
- Declare @sum int
- Exec proc_stu @sum output,64