Loading...

derby-user@db.apache.org

[Prev] Thread [Next]  |  [Prev] Date [Next]

Re: Constraint already exists in Schema 'APP' John Steele Fri Apr 06 10:01:12 2012

I understand that constraints should be unique, but I don't understand why in
that case they can't be reused or something like. If I have for example 100
tables and 50 of those tables have a Foreign Key reference to the same table
I have to create 50 different constraint ID's. That's extremely redundant,
and annoying. 


liborjelinek wrote:
> 
> 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 <[EMAIL PROTECTED]>
> 
>>
>> 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.
>>
>>
> 
> 

-- 
View this message in context: 
http://old.nabble.com/Constraint-already-exists-in-Schema-%27APP%27-tp33564657p33639530.html
Sent from the Apache Derby Users mailing list archive at Nabble.com.