Oracle cascading deletion trigger and oracle trigger
Create table student (-- CREATE a STUDENT TABLE
Id number (10) primary key, -- PRIMARY KEY ID
SNAME VARCHAR2 (20 ),
CLASSNAME VARCHAR2 (20) -- class ID
);
Insert into student values (1, 'Tom ', 1 );
Insert into student values (2, 'jack', 1 );
Insert into student values (3, 'bay ', 2 );
Insert into student values (4, 'john', 3 );
Create table classtab (-- CREATE a class TABLE
Classid number (2) primary key, -- class ID
CNAME VARCHAR2 (20)
);
Insert into classtab values (1, '3g ');
Insert into classtab values (2, 'svse ');
Insert into classtab values (3, 'gis ');
Insert into classtab values (4, 'em ');
-- When a trigger is created to delete a class, all student information of the class is also deleted.
CREATE OR REPLACE TRIGGER MYTRIGGER
AFTER DELETE
ON CLASSTAB
FOR EACH ROW
BEGIN
Delete from student where classname =: old. CLASSID;
END;
Delete from classtab where classid = 2; deleting the third record of the class student table whose CLASSID is 2 in the class table will also be deleted.