Subject Re: Order of execution cascade operations
Author Adam
--- In firebird-support@yahoogroups.com, "lacakus" <lacak@...> wrote:
>
> Hi,
> I have table1 and table2, which references table1 with foreign key
> constraint with "on delete cascade".
> On table2 is defined "after delete" trigger ...
>
> When I delete row from table1 which happens ?
> A:
> 1. row (master) from table1 is deleted
> 2. corresponding rows (detail) are deleted from table2
> 3. trigger on table2 is fired for every deleted row of table2
>
> -or-
> B:
> 1. corresponding rows (detail) are deleted from table2
> 2. trigger on table2 is fired for every deleted row of table2
> 3. row (master) from table1 is deleted
>
> If A is true, then I cannot reference "just deleted" row from
> table1, ... true ?
> (command as : select col1 from table1 where pk1=OLD.fk2 into :var;
>

Delete from Master_table;

1. Before delete events on master table
2. After delete events on master table
3. Before delete events on child table
4. After delete events on child table

It gets more complex where you have multiple child tables. But yes, by
the time you do a select on OLD.fk2 from the master_table, the record
is already gone.

The cascade rule seems to behave like the after delete trigger on the
master table with the highest position.

Adam