Hierarchical Deletion w Cascaded TRIGGERS in SE
Posted in 1995
Topics: Connectivity: ESQL/C, 4GL & Embedded SQL, Triggers, Constraints & Referential Integrity
Using Informix-SE and ESQL/C v5.01
I have several tables organised in a hierarchical (tree) fashion:
a parent has multiple children, which in turn have multiple children,
by defining referential constraints on foreign keys.
I would like to define cascaded TRIGGERS such that by deleting a
record in the top-most parent table, all related records in children
tables will be recursively deleted. Furthermore, I would like to
be able to delete multiple parent records in one SQL statement.
The TRIGGER can be defined as follows:
CREATE TRIGGER del_parent
DELETE ON parent
REFERENCING OLD AS pre_del
FOR EACH ROW (DELETE FROM child
WHERE foreign_key = pre_del.key);
The problem is that the for each parent row, the trigger action (deleting
the child records) will take place AFTER the trigger event (deleting the
parent record). This violates referential constraints since the parent
record cannot be deleted while it is still referenced by child records.
Can anybody suggest a solution, other than using the OnLine server,
or doing the work manually ? Any suggestions will be appreciated.
Johnny Farraj johnny@aztech.demon.co.uk