Re: Quick question re foreign keys.

From: "D'Arcy J(dot)M(dot) Cain" <darcy(at)druid(dot)net>
To: Nis Jørgensen <nis(at)superlativ(dot)dk>
Cc: pgsql-sql(at)postgresql(dot)org, Paul Lambert <paul(dot)lambert(at)autoledgers(dot)com(dot)au>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: Re: Quick question re foreign keys.
Date: 2007-10-24 14:53:43
Message-ID: 20071024105343.582fb4e0.darcy@druid.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Wed, 24 Oct 2007 09:43:10 +0200
Nis Jørgensen <nis(at)superlativ(dot)dk> wrote:
> Well, I have a couple of times had the "need" to have a primary
> key/uniqueness constraint with one column nullable (indicating "Not
> Applicable"). The "problem" is that we have only one NULL, which for
> comparison purposes is interpreted as "Not Known".

Of course. Happens all the time. However, UNIQUE and PRIMARY are not
the same thing. PRIMARY implies that the column uniquely and
definitively identifies the row. If you have NULLs in the column than
it does not meet the criteria. Here are the rules for primary key
taken from http://articles.techrepublic.com.com/5100-22-1045050.html.

- The primary key must uniquely identify each record.
- A record?s primary-key value can?t be null.
- The primary key-value must exist when the record is created.
- The primary key must remain stable?you can?t change the primary-key field(s).
- The primary key must be compact and contain the fewest possible attributes.
- The primary-key value can?t be changed.

--
D'Arcy J.M. Cain <darcy(at)druid(dot)net> | Democracy is three wolves
http://www.druid.net/darcy/ | and a sheep voting on
+1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Otniel Michael 2007-10-25 02:31:11 ERROR: failed to re-find parent key in "pk_ep07"
Previous Message Robins Tharakan 2007-10-24 14:27:44 Re: Quick question re foreign keys.