mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-12-15 08:20:16 +08:00
Improve discussion of using OIDs for identifying rows, fix an instance of
incorrect SGML markup.
This commit is contained in:
parent
6a1e2b3c28
commit
5ae38167cf
@ -1,4 +1,4 @@
|
|||||||
<!-- $PostgreSQL: pgsql/doc/src/sgml/ddl.sgml,v 1.25 2003/11/29 19:51:36 pgsql Exp $ -->
|
<!-- $PostgreSQL: pgsql/doc/src/sgml/ddl.sgml,v 1.26 2004/03/07 04:31:01 neilc Exp $ -->
|
||||||
|
|
||||||
<chapter id="ddl">
|
<chapter id="ddl">
|
||||||
<title>Data Definition</title>
|
<title>Data Definition</title>
|
||||||
@ -77,8 +77,8 @@
|
|||||||
</indexterm>
|
</indexterm>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
To create a table, you use the aptly named <literal>CREATE
|
To create a table, you use the aptly named <command>CREATE
|
||||||
TABLE</literal> command. In this command you specify at least a
|
TABLE</command> command. In this command you specify at least a
|
||||||
name for the new table, the names of the columns and the data type
|
name for the new table, the names of the columns and the data type
|
||||||
of each column. For example:
|
of each column. For example:
|
||||||
<programlisting>
|
<programlisting>
|
||||||
@ -302,18 +302,38 @@ DROP TABLE products;
|
|||||||
</variablelist>
|
</variablelist>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
OIDs are 32-bit quantities and are assigned from a single cluster-wide
|
OIDs are 32-bit quantities and are assigned from a single
|
||||||
counter. In a large or long-lived database, it is possible for the
|
cluster-wide counter. In a large or long-lived database, it is
|
||||||
counter to wrap around. Hence, it is bad practice to assume that OIDs
|
possible for the counter to wrap around. Hence, it is bad
|
||||||
are unique, unless you take steps to ensure that they are unique.
|
practice to assume that OIDs are unique, unless you take steps to
|
||||||
Recommended practice when using OIDs for row identification is to create
|
ensure that this is the case. If you need to identify the rows in
|
||||||
a unique constraint on the OID column of each table for which the OID will
|
a table, using a sequence generator is strongly recommended.
|
||||||
be used. Never assume that OIDs are unique across tables; use the
|
However, OIDs can be used as well, provided that a few additional
|
||||||
combination of <structfield>tableoid</> and row OID if you need a
|
precautions are taken:
|
||||||
database-wide identifier. (Future releases of
|
|
||||||
<productname>PostgreSQL</productname> are likely to use a separate
|
<itemizedlist>
|
||||||
OID counter for each table, so that <structfield>tableoid</>
|
<listitem>
|
||||||
<emphasis>must</> be included to arrive at a globally unique identifier.)
|
<para>
|
||||||
|
A unique constraint should be created on the OID column of each
|
||||||
|
table for which the OID will be used to identify rows.
|
||||||
|
</para>
|
||||||
|
</listitem>
|
||||||
|
<listitem>
|
||||||
|
<para>
|
||||||
|
OIDs should never be assumed to be unique across tables; use
|
||||||
|
the combination of <structfield>tableoid</> and row OID if you
|
||||||
|
need a database-wide identifier.
|
||||||
|
</para>
|
||||||
|
</listitem>
|
||||||
|
<listitem>
|
||||||
|
<para>
|
||||||
|
The tables in question should be created using <literal>WITH
|
||||||
|
OIDS</literal> to ensure forward compatibility with future
|
||||||
|
releases of <productname>PostgreSQL</productname> in which OIDs
|
||||||
|
are not included in all tables by default.
|
||||||
|
</para>
|
||||||
|
</listitem>
|
||||||
|
</itemizedlist>
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
@ -798,7 +818,7 @@ CREATE TABLE orders (
|
|||||||
);
|
);
|
||||||
</programlisting>
|
</programlisting>
|
||||||
Now it is impossible to create orders with
|
Now it is impossible to create orders with
|
||||||
<literal>product_no</literal> entries that do not appear in the
|
<structfield>product_no</structfield> entries that do not appear in the
|
||||||
products table.
|
products table.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
@ -892,7 +912,7 @@ CREATE TABLE order_items (
|
|||||||
|
|
||||||
<para>
|
<para>
|
||||||
To illustrate this, let's implement the following policy on the
|
To illustrate this, let's implement the following policy on the
|
||||||
many-to-many relationship example above: When someone wants to
|
many-to-many relationship example above: when someone wants to
|
||||||
remove a product that is still referenced by an order (via
|
remove a product that is still referenced by an order (via
|
||||||
<literal>order_items</literal>), we disallow it. If someone
|
<literal>order_items</literal>), we disallow it. If someone
|
||||||
removes an order, the order items are removed as well.
|
removes an order, the order items are removed as well.
|
||||||
|
Loading…
Reference in New Issue
Block a user