Subject | Re: Trigger on child table isnt activated when i delete the parent table? cascad |
---|---|
Author | Adam |
Post date | 2006-11-09T23:14:59Z |
--- In firebird-support@yahoogroups.com, "Fabio Gomes" <fabioxgn@...>
wrote:
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
wrote:
>and i
> Hi guys,
>
> I have 2 tables and i set the relationship between them to cascade,
> have a trigger on the child table to delete some stuff on othertable, when
> i delete the row in the child table it works, but when i delete theparent
> (and the cascade option deletes the child table rows too) thistrigger isnt
> activated.No, it never does.
>
> Does firebird always behave this way?
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