Subject Re: [firebird-support] Referential integrity
Author Alan Davies
Hi Alfred
Try this, I have copied and pasted from a working program and just
substituted your file and table names; you don't need triggers:-
ALTER TABLE Attachment ADD FOREIGN KEY (NoteID) REFERENCES Notes
(NoteID) ON UPDATE CASCADE ON DELETE CASCADE;


> Hi
>
> I have the following tables:
>
> CREATE TABLE "Attachment"
> (
> "AttachmentID" SMALLINT NOT NULL, //Primary key
> "NoteID" INTEGER NOT NULL, //Primary key
> "Attachment" BLOB SUB_TYPE 0 SEGMENT SIZE 80,
> "Description" VARCHAR(50),
> "FileName" VARCHAR(50)
> );
>
> CREATE TABLE "Notes"
> (
> "NoteID" INTEGER NOT NULL, //Primary key
> "Description" VARCHAR(250),
> "NoteDate" TIMESTAMP
> );
>
> I want the children(Attachment) to be deleted when the parent(Notes)
are
> deleted.
> First I tried a Foreign key constraint:
> ALTER TABLE "Attachment" ADD CONSTRAINT "FK_Attachment_Notes" FOREIGN
KEY
> ("NoteID") REFERENCES "Notes" ("NoteID") ON DELETE CASCADE;
>
> And then a trigger:
> CREATE TRIGGER "Notes_BD0" FOR "Notes"
> ACTIVE BEFORE DELETE POSITION 0
> AS
> begin
> delete from "Attachment" where "Attachment"."NoteID"
= "Notes"."NoteID";
> end
>
> But whenever I delete Notes the children(Attachment) isn't deleted.
> Can anyone show me the correct way?
>
> Regards
> Alfred Thomas
>
>
>
>
> ------------------------ Yahoo! Groups Sponsor ---------------------~-
->
> Buy Ink Cartridges or Refill Kits for your HP, Epson, Canon or Lexmark
> Printer at MyInks.com. Free s/h on orders $50 or more to the US &
Canada.
> http://www.c1tracking.com/l.asp?cid=5511
> http://us.click.yahoo.com/mOAaAA/3exGAA/qnsNAA/67folB/TM
> ---------------------------------------------------------------------
~->
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>

Alan J Davies
Tel: +44 (0)1926 842069
Fax: +44 (0)1926 843755