oracle-databasetriggersoracle10greferential

referential actions with trigger


I have this task to emulate a referential action with a trigger. The task itself is: Give an example of how to use a trigger to emulate a referential action.

I know hot to use triggers and referential actions but combined I just don't really get it, and the question itself.


Solution

  • Given that the least objectionable of the options you listed is to do a cascading delete when a parent row is removed

    CREATE OR REPLACE TRIGGER trigger_name
      AFTER DELETE ON parent_table
      FOR EACH ROW
    BEGIN
      DELETE FROM child_table
       WHERE parent_id = :old.parent_id;
    
      <<repeat for each child table>>
    END;