SQL 中的存储过程: 1.在建立存储过程之前检查所命名的存储过程是否应经存在。(因为如果同名存储过程已经存在,新的存储过程将不被建立) if exists(select * from sysobject where name='proc name' and type='p') drop proc proc name go 2.定义存储过程 create proc test @gradel int, --定义变量 @gradeh int output --定义输出变量 as ... go 3.执行存储过程 declare @l int,@h int exec proc test 34,@h output print @h ---------------------------------------------- 下面以一个例子说明: 输入两个分数,要求写两个存储过程,一个对输入分数排序,另一个查询两分数段之间的成绩: 一共有三个表: s表:(s#:学生号,sname:学生姓名,age:年龄,sex:性别) c表:(c#:课程号,cname:课程名,teacher:老师) sc表:(s#,c#,grade) if exists(select * from sysobjects where name='sort' create proc sort as if exists(select * from sysobjects where name='search' and type='p') create proc search
参考:http://hi.baidu.com/rosalind1717/blog/item/bcb26ceea5a418212cf534ce.html
http://hi.baidu.com/isbx/blog/item/3e06ae514c35ac878d543094.html
|
关于Sql存储过程
最新推荐文章于 2024-09-23 09:14:08 发布