Re: Primary Key Best Practices Poll
From: Guinness Mann (gmann_at_dublin.com)
Date: 03/12/04
- Next message: Ryan Rushton: "Selecting all but one DB column"
- Previous message: cvegas: "Re: Double Post"
- In reply to: John Baro: "Re: Primary Key Best Practices Poll"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 11 Mar 2004 20:14:20 -0700
On Wed, 03 Mar 2004 22:30:04 GMT, "John Baro"
<johnb@NOSPAMmesware.com.au> wrote:
> I believe that when a primary key logically consists of two or more
> columns it should be created as such.
I try very hard to find a natural primary key, but instances where that
is unreasonable are pretty common. Take the classic invoice line-item
example. The only natural key is a combination of all the attributes in
the table.
So other tables that wanted to have a foreign key into the invoice
line-item table would have to replicate the entire tuple in their own
table. Where's the sense in that?
In that case I would do like your friends suggest and put a unique
constraint on the set of all the attributes and add a tuple-identifier
for easy access by related tables.
In fact, any time the natural key gets over about two attributes I'd
probably do that.
There are better unique identifiers than Identity, though. Some kind of
computed value, like a hash, that can be generated from the data ensures
that if you ever have to merge two like tables you won't have to worry
about Identity-collisions...
-- Rick
- Next message: Ryan Rushton: "Selecting all but one DB column"
- Previous message: cvegas: "Re: Double Post"
- In reply to: John Baro: "Re: Primary Key Best Practices Poll"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|