Return-Path: X-Original-To: apmail-db-derby-user-archive@www.apache.org Delivered-To: apmail-db-derby-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 5391C91FA for ; Fri, 6 Apr 2012 16:28:00 +0000 (UTC) Received: (qmail 4080 invoked by uid 500); 6 Apr 2012 16:28:00 -0000 Delivered-To: apmail-db-derby-user-archive@db.apache.org Received: (qmail 4008 invoked by uid 500); 6 Apr 2012 16:27:59 -0000 Mailing-List: contact derby-user-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: List-Id: Reply-To: "Derby Discussion" Delivered-To: mailing list derby-user@db.apache.org Received: (qmail 4000 invoked by uid 99); 6 Apr 2012 16:27:59 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 06 Apr 2012 16:27:59 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=5.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of lists@nabble.com designates 216.139.236.26 as permitted sender) Received: from [216.139.236.26] (HELO sam.nabble.com) (216.139.236.26) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 06 Apr 2012 16:27:52 +0000 Received: from isper.nabble.com ([192.168.236.156]) by sam.nabble.com with esmtp (Exim 4.72) (envelope-from ) id 1SGC0Z-0000pJ-LN for derby-user@db.apache.org; Fri, 06 Apr 2012 09:27:31 -0700 Message-ID: <33639530.post@talk.nabble.com> Date: Fri, 6 Apr 2012 09:27:31 -0700 (PDT) From: John Steele To: derby-user@db.apache.org Subject: Re: Constraint already exists in Schema 'APP' In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Nabble-From: programjsteele@gmail.com References: <33564657.post@talk.nabble.com> 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 > >> >> 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.