db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Libor Jelinek <ljeli...@virtage.com>
Subject Re: Constraint already exists in Schema 'APP'
Date Thu, 05 Apr 2012 08:38:59 GMT
Hello John!
Constaint name must be unique at schema level (in your case APP schema). In
other words name for example first FK constaint as FK_PATIENT_PERSON_ID and
second as FK_EMPLOYEE_PERSON_ID (FK_table_referencingColumn).

Hope that helps!
Libor

2012/4/4 John Steele <programjsteele@gmail.com>

>
> I have three tables Person, Patient, and Employee. Both Patient and
> Employee
> have a Foreign Key to Person; however, when creating the constraint for the
> second time I get the following error:
>
> Constraint 'PERSON_FK' already exists in Schema 'APP'.
>
> [code]
> CREATE TABLE PERSON (
>        PERSON_ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH
> 1,
> INCREMENT BY 1)
> );
>
> CREATE TABLE PATIENT (
>        PATIENT_ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START
> WITH 1,
> INCREMENT BY 1),
>        PERSON_ID INTEGER NOT NULL
> );
>
> ALTER TABLE PATIENT
>        ADD CONSTRAINT PERSON_FK Foreign Key (
>                PERSON_ID)
>        REFERENCES PERSON (
>                PERSON_ID);
>
>
> CREATE TABLE EMPLOYEE (
>        EMPLOYEE_ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START
> WITH 1,
> INCREMENT BY 1),
>        PERSON_ID INTEGER NOT NULL
> );
>
> ALTER TABLE EMPLOYEE
>        ADD CONSTRAINT PERSON_FK Foreign Key (
>                PERSON_ID)
>        REFERENCES PERSON (
>                PERSON_ID);
> [/code]
>
> What do you do in this situation? Do you only create on constraint and then
> reference it when using it again? If so, how?
>
> Thanks,
> John Steele
>
> --
> View this message in context:
> http://old.nabble.com/Constraint-already-exists-in-Schema-%27APP%27-tp33564657p33564657.html
> Sent from the Apache Derby Users mailing list archive at Nabble.com.
>
>

Mime
View raw message