Re: Is PRIMARY KEY the same as UNIQUE NOT NULL?

From: Harald Fuchs <hari(dot)fuchs(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Is PRIMARY KEY the same as UNIQUE NOT NULL?
Date: 2016-01-31 09:00:47
Message-ID: 87mvrm6s3k.fsf@hf.protecting.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Ben Leslie <benno(at)benno(dot)id(dot)au> writes:

> "Technically, PRIMARY KEY is merely a combination of UNIQUE and NOT NULL"
>
> I wanted to clarify if that was, technically, true.

Yes, but see below.

> "identifying a set of columns as primary key also provides metadata
> about the design of the schema, as a primary key implies that other
> tables can rely on this set of columns as a unique identifier for
> rows."

This means that e.g. you can use

ALTER TABLE othertbl FOREIGN KEY (refid) REFERENCES mytbl

without specifying the column(s) of mytbl. This implies that there can
be only one primary key (possibly covering more than one column), and
that's the second difference to UNIQUE NOT NULL.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2016-01-31 17:02:38 Re: Is PRIMARY KEY the same as UNIQUE NOT NULL?
Previous Message Ben Leslie 2016-01-31 06:41:42 Is PRIMARY KEY the same as UNIQUE NOT NULL?