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