if exists (select * from sysobjects where name='stu_pr' and type='P')begin
drop procedure stu_pr print '已删除! '
end
else
print '不存在,可创建! '
create procedure stu_pr
as
select distinct * from student s
left join sc on s.sno=sc.sno
left join course c on c.Cno=sc.Cno where classno='051'
exec stu_pr
if exists (select * from sysobjects where name='stu_proc1' and type='P')
begin
drop procedure stu_proc1 print '已册删除!'
end
else
print '不存在,可创建! '
create procedure stu_proc1
@sdept varchar(10)='%', @sname varchar(10)='林%'
as
select Sname , s.Sno, YEAR(getdate ( ) ) -YEAR(Birth) Age, Cname ,Grade from student s, Course c,sc
where s.Sno=sc.sno and c.Cno=sc.Cno
and s.Sname like @sname and s.sdept like @sdept
exec stu_proc1
exec stu_proc1 @sdept='%', @sname ='林%'
if exists (select name from sysobjects where name='student_sc' and type='P')
drop procedure student_sc
go
create procedure student_sc
@sno_begin varchar (10)='20110001 ',@sno_end varchar (10)='20110103'
as
select s.Sno,Sname , SUM (grade) total_grade from student s,sc
where s.sno=sc.sno and s.sno between @sno_begin and @sno_end
group by s.sno ,sname
exec student_sc
if exists (select name from sysobjects where name='Course_sum' and type='P ')
drop procedure course_sum
create procedure course_sum @cname varchar(10)='告'
as
select SUM(grade) total_grade , COUNT(sno)sno from course c, sc
where c.Cno=sc.Cno and Cname like cname
执行:
exec course_sum '高数'
create procedure sum_grade2
@cname varchar (10) , @@sum smallint output
as
select @@sum=sum ( grade)from course c , sc
where c.Cno=sc.Cno and Cname like cname
declare @@sumgrade smallint
exec sum_grade2 '高数',@@sumgrade output if @@sumgrade<100
begin
print '高数的总成绩为:'+CAST(@@sumgrade as varchar(20))+',其总分未达到分。'
end
else
print '高数的总成绩为:'+CAST(@@sumgrade As varchar (20))+'。'
create procedure update_sc
@cno varchar(10),@sno varchar (10) , @grade int with recompile,encryption--重编译,加密
as
update sc
set grade=@grade
where sc.cno=@cno and sc.sno=@sno
exec update_sc '001','20110001','80'
sp_helptext student_sc
syscomments)
select o.id, c.text
from sysobjects o inner join syscomments c
on o.id = c.id
where o.type = 'p' and o.name = 'student_sc'
alter procedure stu_pr
@sno varchar (10)
as
select distinct * from student
where sno='20110001'
exec stu_pr @sno=’2011001’
drop procedure stu_pr
(2)查看存储过程`stu_pr`,并将该过程修改为查询051班女生的所有资料。可编程性→存储过程→>stu _pr,右击stu _pr→>修改.
(3) 修改sQL语句,使之能查询051班所有女生的资料的存储过程
(3)删除存储过程stu_pr
选择存储过程stu _pr,右击,选择“删除”
免责申明:
本文系转载,版权归原作者所有,如若侵权请联系我们进行删除!
《数据治理行业实践白皮书》下载地址:https://fs80.cn/4w2atu
《数栈V6.0产品白皮书》下载地址:https://fs80.cn/cw0iw1
想了解或咨询更多有关袋鼠云大数据产品、行业解决方案、客户案例的朋友,浏览袋鼠云官网:https://www.dtstack.com/?src=bbs
同时,欢迎对大数据开源项目有兴趣的同学加入「袋鼠云开源框架钉钉技术群」,交流最新开源技术信息,群号码:30537511,项目地址:https://github.com/DTStack