-- 第一题createfunction func1(@coursenamechar(30))-- 定义函数returnsfloatasbegindeclare@avg_scorefloatselect@avg_score=avg(score)from sc, c
where c.cname =@coursenameand sc.cno = c.cno
return@avg_scoreend
go -- 消除批处理警告select dbo.func1('高数') avg_score -- 调用函数
go -- 消除批处理警告-- 第二题createproc update_score
@coursenamechar(30)asbegindeclare@idchar(12),@oldint,@c_idchar(6),@newint;declare cur cursorforselect sno, score, sc.cno from sc, c where c.cname =@coursenameand sc.cno = c.cno
open cur
fetchnextfrom cur into@id,@old,@c_id;while @@FETCH_STATUS=0beginif@old>90and@old<95set@new=@old+5;elseif@old<=90and@old>90set@new=@old+3;elseif@old<=80and@old>70set@new=@old+2;elseif@old<=70and@old>60set@new=@old+1;update sc set score =@newwhere sno =@idand sc.cno =@c_id;fetchnextfrom cur into@id,@old,@c_id;endclose cur
deallocate cur
endexec dbo.update_score '高等数学1'