Subject | Re: [firebird-support] Referential integrity |
---|---|
Author | Alan Davies |
Post date | 2004-05-04T08:25:45Z |
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;
Tel: +44 (0)1926 842069
Fax: +44 (0)1926 843755
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;
> Hiare
>
> 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)
> deleted.KEY
> First I tried a Foreign key constraint:
> ALTER TABLE "Attachment" ADD CONSTRAINT "FK_Attachment_Notes" FOREIGN
> ("NoteID") REFERENCES "Notes" ("NoteID") ON DELETE CASCADE;= "Notes"."NoteID";
>
> And then a trigger:
> CREATE TRIGGER "Notes_BD0" FOR "Notes"
> ACTIVE BEFORE DELETE POSITION 0
> AS
> begin
> delete from "Attachment" where "Attachment"."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 LexmarkCanada.
> Printer at MyInks.com. Free s/h on orders $50 or more to the US &
> http://www.c1tracking.com/l.asp?cid=5511~->
> http://us.click.yahoo.com/mOAaAA/3exGAA/qnsNAA/67folB/TM
> ---------------------------------------------------------------------
>Alan J Davies
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
Tel: +44 (0)1926 842069
Fax: +44 (0)1926 843755