Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 9E62F475C60; Mon, 19 Aug 2002 14:25:56 -0400 (EDT) Received: from mail.benoit-computers.com (ptr-207-54-114-165.ptr.terago.ca [207.54.114.165]) by postgresql.org (Postfix) with ESMTP id A1718475BBB; Mon, 19 Aug 2002 14:25:55 -0400 (EDT) Received: from ([]) by mail.benoit-computers.com (Merak 4.4.2) with SMTP id DBFC9CCB; Mon, 19 Aug 2002 13:24:11 -0500 From: "Darrin Domoney" To: , , Subject: Re: [SQL] Urgent - SQL Unique constraint error (long) Date: Mon, 19 Aug 2002 13:25:24 -0500 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0) X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 In-Reply-To: <20020819103903.D32160-100000@megazone23.bigpanda.com> Importance: Normal X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200208/214 X-Sequence-Number: 5329 Stephan, Thanks for the response but the answer is no. Owing to the ongoing issue with inherited tables in 7.x I have opted to create three tables: Contains generic traits regardless of "class or role". Person -> PK person_id Staff as certain "class" of person. Staff -> PK staff_id FK person_id Contact as another "class" of person. Contact -> PK contact_id FK person_id Phone numbers relate to any "class" but are related back to the originator by using "person_id". Darrin -----Original Message----- From: Stephan Szabo [mailto:sszabo@megazone23.bigpanda.com] Sent: August 19, 2002 12:41 PM To: Darrin Domoney Cc: pgsql-sql@postgresql.org; pgsql-novice@postgresql.org; pgsql-admin@postgresql.org Subject: Re: [SQL] Urgent - SQL Unique constraint error (long) On Mon, 19 Aug 2002, Darrin Domoney wrote: > An admitted newbie to postgresql I am trying to commit a new design > my development server using pgAdminII. > > Everything appears to work OK but I am having real grief with my > SQL generating errors - most of which I have cleared myself but > one that I am unsure how to handle: > > UNIQUE constraint for matching given keys for referenced table "staff" > not found > > Below is the SQL code that I am tring to load to build out my database > skeleton: > > CREATE TABLE staff > ( > staff_id serial NOT NULL, > person_id int NOT NULL, > active_staff boolean NOT NULL, > pay_rate decimal(8,2), > discounted_rate decimal(8,2), > discount_break int, > organization_id int NOT NULL, > PRIMARY KEY (staff_id) > ); > ALTER TABLE phone_number ADD CONSTRAINT staff_phone > FOREIGN KEY ( person_id ) > REFERENCES staff ( person_id ) > NOT DEFERRABLE; The target of a references constraint must be in a unique constraint. Here you're referencing person_id which is not the key of staff. Are you sure you don't want to be linking staff_id instead?