mirror of
https://github.com/postgres/postgres.git
synced 2025-08-22 21:53:06 +03:00
Improve documentation about PRIMARY KEY constraints.
Get rid of the false implication that PRIMARY KEY is exactly equivalent to UNIQUE + NOT NULL. That was more-or-less true at one time in our implementation, but the standard doesn't say that, and we've grown various features (many of them required by spec) that treat a pkey differently from less-formal constraints. Per recent discussion on pgsql-general. I failed to resist the temptation to do some other wordsmithing in the same area.
This commit is contained in:
@@ -506,25 +506,25 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXI
|
||||
<term><literal>PRIMARY KEY ( <replaceable class="PARAMETER">column_name</replaceable> [, ... ] )</> (table constraint)</term>
|
||||
<listitem>
|
||||
<para>
|
||||
The primary key constraint specifies that a column or columns of a table
|
||||
can contain only unique (non-duplicate), nonnull values.
|
||||
Technically, <literal>PRIMARY KEY</literal> is merely a
|
||||
combination of <literal>UNIQUE</> and <literal>NOT NULL</>, but
|
||||
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.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Only one primary key can be specified for a table, whether as a
|
||||
The <literal>PRIMARY KEY</> constraint specifies that a column or
|
||||
columns of a table can contain only unique (non-duplicate), nonnull
|
||||
values. Only one primary key can be specified for a table, whether as a
|
||||
column constraint or a table constraint.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
The primary key constraint should name a set of columns that is
|
||||
different from other sets of columns named by any unique
|
||||
constraint defined for the same table.
|
||||
different from the set of columns named by any unique
|
||||
constraint defined for the same table. (Otherwise, the unique
|
||||
constraint is redundant and will be discarded.)
|
||||
</para>
|
||||
|
||||
<para>
|
||||
<literal>PRIMARY KEY</literal> enforces the same data constraints as
|
||||
a combination of <literal>UNIQUE</> and <literal>NOT NULL</>, but
|
||||
identifying a set of columns as the primary key also provides metadata
|
||||
about the design of the schema, since a primary key implies that other
|
||||
tables can rely on this set of columns as a unique identifier for rows.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
Reference in New Issue
Block a user