触发器 完美运行
CREATE TRIGGER NO5 ON SC FOR insert,delete,update AS declare @totalScore int declare @score1 int declare @score2 int declare @credit int declare @Cno char(4) declare @Sno char(10) select @score1=l.Grade from inserted l select @score2=l.Grade from deleted l/*修改时删掉的那个分数*/ select @Cno=l.Cno from inserted l select @Sno=l.Sno from inserted l if(@score1>=60) begin select @credit=Ccredit from Course where Course.Cno=@Cno select @totalScore=(select totalScore from Student where Sno=@Sno)+@credit update Student set totalScore=@totalScore where Sno=@Sno end if update(grade) begin select @score2=l.Grade from inserted l select @score1=l.Grade from deleted l/*修改时删掉的那个分数*/ select @credit=Ccredit from Course where Course.Cno=@Cno select @Cno=l.Cno from inserted l select @Sno=l.Sno from inserted l if(@score1>60 and @score2<60)--把及格改成不及格 update Student set totalScore=totalScore-@credit where Sno=@Sno else if(@score2>60 and @score1<60)--把不及格改成及格 update Student set totalScore=totalScore+@credit where Sno=@Sno end
积跬步以致千里,积小流以成江海。
2016年5月之前的博文发布于51cto,链接地址:shamrock.blog.51cto.com
2016年5月之后博文发布与cnblogs上。
Github地址 https://github.com/umgsai
Keep moving~!!!
2016年5月之前的博文发布于51cto,链接地址:shamrock.blog.51cto.com
2016年5月之后博文发布与cnblogs上。
Github地址 https://github.com/umgsai
Keep moving~!!!

浙公网安备 33010602011771号