触发器 在学生表中删除学生的同时删除选课表的信息 CREATE TRIGGER students_delete_before BEFORM DELETE ON students FOR EACH ROW BEGIN DELETE FROM sc WHERE Sno=old.Sno; END; 更新选课表信息 CREATE TRIGGER students_update_after AFTER UPDATE ON students FOR EACH ROW BEGIN UPDATE sc SET Sno=new.Sno WHERE Sno=old.Sno; END; 学分录入(成绩大于60) CREATE TRIGGER sc_install_after AFTER UPDATE ON sc FOR EACH ROW BEGIN DECLARE xf SAMLLINT; SELECT Ccredit INTO xf FORM course WHERE Cno=new.Cno; IF new.Grade>=60 THEN UPDATE students SET Scredit+xf WHERE Sno=new.Sno; END IF; END;这段代码找出错误并改正
时间: 2024-03-25 14:40:53 浏览: 66
在第三个触发器中,声明变量的语句中 "SAMLLINT" 应该为 "SMALLINT"。同时,在更新语句后面应该加上 SET 关键字,将修改后的学分值赋值给 Scredit 字段。修改后的代码如下:
```
CREATE TRIGGER sc_install_after AFTER UPDATE ON sc FOR EACH ROW
BEGIN
DECLARE xf SMALLINT;
SELECT Ccredit INTO xf FROM course WHERE Cno=new.Cno;
IF new.Grade >= 60 THEN
UPDATE students SET Scredit = Scredit + xf WHERE Sno = new.Sno;
END IF;
END;
```
阅读全文