0

例如,您删除了一个表中的一行,它链接到相应表中的条目。此触发器应在从第一个表中删除元组时从第二个表中删除元组(假设它们的外键匹配的位置)。换句话说,级联删除。假装无法将级联删除选项添加到表中。

我正在使用 Oracle/SQL Plus,这是我的尝试:

CREATE OR REPLACE TRIGGER delCascade
    BEFORE DELETE ON student
    REFERENCING OLD AS oldRow
    FOR EACH ROW    
BEGIN
    DELETE FROM taking
    WHERE taking.studentnum = oldRow.studentnum;
END;
/

我不断收到警告:

Warning: Trigger created with compilation errors.
4

2 回答 2

2

尝试这个

CREATE OR REPLACE TRIGGER delCascade
    BEFORE DELETE ON student
    REFERENCING OLD AS oldRow
    FOR EACH ROW    
BEGIN
    DELETE FROM taking
    WHERE taking.studentnum = :oldRow.studentnum;
END;
于 2013-04-23T05:27:58.333 回答
0

给定一个

STUD(rollno, name, birthdate)
RESULT(rollno, marks)

1)编写一个触发器,RESULT如果​​学生记录被删除,则从表中删除所有相关记录。

create or replace trigger del_trg
after delete on stud_trg
for each row
begin
    if deleting then
        delete from result where stud_trg.rollno=result.rollno;
    end if;
end;    
于 2016-12-06T02:58:14.323 回答