On Apr 25, 3:16 pm, "Kai Kuehne" <[EMAIL PROTECTED]> wrote:
>
> I'm a bit confused on how do it 'right(tm)'. Is there a
> rule or how would you do it?
>

You're asking about surrogate and natural keys:

     http://en.wikipedia.org/wiki/Surrogate_key
     http://en.wikipedia.org/wiki/Natural_key

Peruse those at your leisure.  I'll wait...

Okay, with those articles in mind, I would recommend you always use a
surrogate key as your primary key.

There's no harm in having unique columns in addition to your primary
key (as you describe).  The nut of the problem around natural keys,
IMHO, is that the rules that make them natural keys today can change
such that they are no longer keys tomorrow.  When that happens, you
float your resume and find a new gig.

The only time you don't need a surrogate key is in cross reference, or
many-to-many, tables.  They consist of two columns, each pointing to
tables being related.  Django hides the 'detail' of that relationship
from you, but if you check the SQL it spits out, you'll see that they
are, in fact, there.

Don't take my recommendation as authoritative.  I'm not a DBA by
trade, I'm a code monkey.  Take the time to read up on the subject.
The Wikipedia pages are a good start.  :-)

In my personal experience, I can not think of a database I've worked
with in my career that used natural keys (15 years experience, so you
can frame that statement).


doug.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to