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 9F52F9DC997 for ; Wed, 14 Dec 2005 06:25:08 -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 32369-01-2 for ; Wed, 14 Dec 2005 06:25:10 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from smtp8.libero.it (smtp8.libero.it [193.70.192.92]) by postgresql.org (Postfix) with ESMTP id 799CE9DC9A3 for ; Wed, 14 Dec 2005 06:25:06 -0400 (AST) Received: from localhost (172.16.1.75) by smtp8.libero.it (7.0.027-DD01) id 439D91AB00323C9B for pgsql-sql@postgresql.org; Wed, 14 Dec 2005 11:25:08 +0100 Received: from smtp20.libero.it ([172.16.1.77]) by localhost (asav17.libero.it [193.70.193.4]) (amavisd-new, port 10024) with ESMTP id 09269-09-3 for ; Wed, 14 Dec 2005 11:25:07 +0100 (CET) Received: from [172.16.0.5] (ppp-103-202.24-151.libero.it [151.24.202.103]) by smtp20.libero.it (Postfix) with ESMTP id 894D350758 for ; Wed, 14 Dec 2005 11:25:06 +0100 (MET) Message-ID: <439FF36F.1040004@moonwatcher.it> Date: Wed, 14 Dec 2005 11:26:55 +0100 From: Gianluca Riccardi User-Agent: Mozilla/5.0 (X11; U; Linux i686; it-IT; rv:1.7.8) Gecko/20050927 Debian/1.7.8-1sarge3 X-Accept-Language: it MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Re: DB design and foreign keys References: <439F0FE8.1050503@moonwatcher.it> <439F1A23.40202@archonet.com> In-Reply-To: <439F1A23.40202@archonet.com> Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Scanned: with antispam and antivirus automated system at libero.it X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200512/116 X-Sequence-Number: 23658 [cut] > > It means what it says. You have defined table orders with a primary > key of (id,order_code). This means that the combination of > (id,order_code) must be unique. yes, that was my thought, and in that context, i thought it could be correct in order to have uniqueness for creating foreign keys > So - these could all exist at the same time: > (1,1), (1,2), (2,1), (2,2) > You could not then add another (1,2) combination. yes, again, i thought that was the uniqueness i needed... > > Since id and order_code are both just automatically-generated numbers > in the orders table it doesn't add anything to make both of them part > of a primary-key. I would delete the id column altogether and just > have the order_code as the primary-key (since "order_code" carries > more meaning to a human than "id"). This means your order_items table > can then safely reference the order_code it wants to. > HTH sure it did, thanks for your response, best regards, Gianluca Riccardi