pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Gianluca Riccardi <ml-reader@moonwatcher.it>
To: pgsql-sql@postgresql.org
Subject: Re: DB design and foreign keys
Date: Wed, 14 Dec 2005 11:26:55 +0100
Message-ID: <439FF36F.1040004@moonwatcher.it> (raw)
In-Reply-To: <439F1A23.40202@archonet.com>
References: <439F0FE8.1050503@moonwatcher.it>
	<439F1A23.40202@archonet.com>

[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



view thread (12+ messages)  latest in thread

Message-ID: <439FF36F.1040004@moonwatcher.it>
Permalink:  ../439FF36F.1040004@moonwatcher.it/
Also on:    postgresql.org/message-id/439FF36F.1040004@moonwatcher.it

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: ml-reader@moonwatcher.it
  Subject: Re: DB design and foreign keys
  In-Reply-To: <439FF36F.1040004@moonwatcher.it>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox