You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by Amir Michail <am...@gmail.com> on 2007/06/28 17:57:29 UTC
adding foreign key that refers to primary key of same table
Hi,
How do you add a foreign key to an existing table that refers to the
primary key of that table?
Amir
RE: adding foreign key that refers to primary key of same table
Posted by "Todorovich, Milo" <Mi...@pamperedchef.com>.
Just like any other foreign key.
This example will work:
CREATE TABLE PERSON(
ID INTEGER GENERATED BY DEFAULT AS IDENTITY(START WITH 1) NOT
NULL PRIMARY KEY,
OTHER_PERSON_ID INTEGER):
ALTER TABLE PERSON ADD CONSTRAINT PERSON_FK1 KEY(OTHER_PERSON_ID)
REFERENCES PERSON(ID) ;
-----Original Message-----
From: Amir Michail [mailto:amichail@gmail.com]
Sent: Thursday, June 28, 2007 10:57 AM
To: Derby Discussion
Subject: adding foreign key that refers to primary key of same table
Hi,
How do you add a foreign key to an existing table that refers to the
primary key of that table?
Amir