Subject Re: [firebird-support] AW: Sample Constraint between Parent-Child tables
Author Lucas Franzen
Namit Nathwani schrieb:

> Hi Steffen
>
> At 01:13 pm 13/10/2004, you wrote:
>
>>What do you mean?
>>Foreign keys can do that.
>
>
> Yes but how.

CREATE TABLE PARENT (
PARENT_ID INTEGER NOT NULL,
PARENT_NAME VARCHAR(40),
CONSTRAINT PK_PARENT PRIMARY KEY ( PARENT_ID )
);


CREATE TABLE CHILD (
CHILD_ID INTEGER NOT NULL,
PARENT_ID INTEGER,
CHILD_NAME VARCHAR(40),
CONSTRAINT PK_PARENT PRIMARY KEY ( PARENT_ID )
);

ALTER TABLE CHILD ADD CONSTRAINT
FK_PARENT_CHILD FOREIGN KEY ( PARENT_ID )
REFERENCES PARENT ( PARENT_ID )
ON DELETE CASCADE;

Note:
You have to have exclusive access to add foreign keys (otherwise you'll
get the OBJECT IS IN USE error).
See the docs for the options for DELETE, UDPATE actions.


Luc.