Re: unique constraint instead of primary key? what disadvantage(ODBC usage)?

From: "BigSmoke" <bigsmoke(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: unique constraint instead of primary key? what disadvantage(ODBC usage)?
Date: 2006-02-09 16:22:59
Message-ID: 1139502179.764894.35960@o13g2000cwo.googlegroups.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

If my tables have one or more UNIQUE constraints/indices, I still add a
"id SERIAL PRIMARY KEY" field to most of my tables. This makes
referencing easier and faster. It also improves consistency, which is
never a bad thing in my opinion.

As far as I know, though, PRIMARY KEY does the same thing as UNIQUE NOT
NULL in PostgreSQL.

The reason that PRIMARY KEY can't be NULL and _has to be_ UNIQUE is
that it is the primary means of identifying a given record in a table.
If you don't have PRIMARY KEY that is UNIQUE and NOT NULL, how are you
going to identify (or reference) individual records? PostgreSQL won't
allow you to reference more than one row for what I came to believe are
very good reasons.

- Rowan

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Andreas Roth 2006-02-09 17:11:24 Change definition of a view
Previous Message BigSmoke 2006-02-09 16:13:59 Re: Non Matching Records in Two Tables