Subject Re: Trigger on child table isnt activated when i delete the parent table? cascad
Author Adam
--- In firebird-support@yahoogroups.com, "Fabio Gomes" <fabioxgn@...>
wrote:
>
> Hi guys,
>
> I have 2 tables and i set the relationship between them to cascade,
and i
> have a trigger on the child table to delete some stuff on other
table, when
> i delete the row in the child table it works, but when i delete the
parent
> (and the cascade option deletes the child table rows too) this
trigger isnt
> activated.
>
> Does firebird always behave this way?

No, it never does.

Let me know how you go:

---

CREATE EXCEPTION E 'TEST';

CREATE TABLE A (
AID INTEGER NOT NULL PRIMARY KEY
);

CREATE TABLE B (
BID INTEGER NOT NULL,
AID INTEGER,
CONSTRAINT PK_B PRIMARY KEY (BID),
CONSTRAINT FK_A FOREIGN KEY (AID) REFERENCES A(AID) ON UPDATE CASCADE
ON DELETE CASCADE
);

SET TERM ^ ;

CREATE OR ALTER TRIGGER B_BD FOR B
ACTIVE BEFORE DELETE POSITION 0
AS
BEGIN
EXCEPTION E;
END
^

SET TERM ; ^

COMMIT;

INSERT INTO A VALUES (1);
INSERT INTO B VALUES (1,1);

COMMIT;

DELETE FROM A;

---

If your trigger isn't working, don't confuse that with it not firing.
Perhaps you are trying to query the value from the parent which was
just deleted.

Adam