Oracle cascading deletes can be implemented using triggers, but the simplest is to directly establish the primary foreign key relationship of the table and set the cascade Delete for the column.
------created the class table and set the ID field as the primary key.
1 --Create Table2 Create TableCLASS3 (4IdVARCHAR2(2) not NULL,5Class_nameVARCHAR2( -)6 )7 Alter TableCLASS8 Add constraintPk_classPrimary Key(ID)
------created the students table and set the ID field as the primary key, class_id as a foreign key and cascade Delete.
1 --Create Table2 Create TableSTUDENTS3 (4IdVARCHAR2(4) not NULL,5class_idVARCHAR2(2) not NULL,6Stu_nameVARCHAR2( -),7Stu_age Number8 )9 Ten Alter TableSTUDENTS One Add constraintPk_stuPrimary Key(ID) A - Alter TableSTUDENTS - Add constraintFk_stuForeign Key(class_id) the ReferencesCLASS (ID) on Delete Cascade;
This removes the class ID and the student who belongs to it will be deleted.
------Delete primary Key original key
ALTER TABLE DROP CONSTRAINT Pk_media_user
Oracle Cascade Delete