X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id A12E79DC88E for ; Tue, 13 Dec 2005 14:33:06 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 74917-01 for ; Tue, 13 Dec 2005 14:33:00 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.199]) by postgresql.org (Postfix) with ESMTP id D7BC69DC895 for ; Tue, 13 Dec 2005 14:32:58 -0400 (AST) Received: by wproxy.gmail.com with SMTP id 57so1708722wri for ; Tue, 13 Dec 2005 10:32:59 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=PWwGfxYUIdQHT+KjjlsEEiiXfxgFj+ZjD3GjRPrEEyZXg5cImy2ZORIbBqTNxd+DdXntc1nUODytDcleVo4b1gglqfC4/wsZbrsVkotx5TnlaOhZrVvVubggmfMO+/l0pk8thawh5iBPNA/Ha96In5Evh4ArDK5GjUJpGFPspzg= Received: by 10.54.111.15 with SMTP id j15mr1435361wrc; Tue, 13 Dec 2005 10:32:58 -0800 (PST) Received: by 10.54.98.6 with HTTP; Tue, 13 Dec 2005 10:32:58 -0800 (PST) Message-ID: Date: Tue, 13 Dec 2005 13:32:58 -0500 From: Jaime Casanova To: Gianluca Riccardi Subject: Re: DB design and foreign keys Cc: pgsql-sql@postgresql.org In-Reply-To: <439F0FE8.1050503@moonwatcher.it> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <439F0FE8.1050503@moonwatcher.it> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.118 required=5 tests=[AWL=0.118] X-Spam-Score: 0.118 X-Spam-Level: X-Archive-Number: 200512/101 X-Sequence-Number: 23643 [...unnecesary...] > CREATE TABLE orders ( > id serial, > order_code serial, > customer_code integer REFERENCES customers (customer_code) NOT NULL, > order_date time without time zone NOT NULL, > remote_ip inet NOT NULL, > order_time timestamp with time zone NOT NULL, > order_type varchar(10) NOT NULL, > state varchar(10) NOT NULL, > PRIMARY KEY (id, order_code) ^^^^^^^^^^^^^^^^^^^ > ); [...unnecesary...] > > CREATE TABLE order_items ( > id serial, > order_code integer REFERENCES orders (order_code) NOT NULL, ^^^^^^^^^= ^^^^^ [...unnecesary...] > ERROR: there is no unique constraint matching given keys for referenced > table "orders" this is because the PK in the orders table has two fields not one... so it founds no unique index on orders(order_code) -- Atentamente, Jaime Casanova (DBA: DataBase Aniquilator ;)