|
1 | | -<!-- $PostgreSQL: pgsql/doc/src/sgml/ddl.sgml,v 1.25 2003/11/29 19:51:36 pgsql Exp $ --> |
| 1 | +<!-- $PostgreSQL: pgsql/doc/src/sgml/ddl.sgml,v 1.26 2004/03/07 04:31:01 neilc Exp $ --> |
2 | 2 |
|
3 | 3 | <chapter id="ddl"> |
4 | 4 | <title>Data Definition</title> |
|
77 | 77 | </indexterm> |
78 | 78 |
|
79 | 79 | <para> |
80 | | - To create a table, you use the aptly named <literal>CREATE |
81 | | - TABLE</literal> command. In this command you specify at least a |
| 80 | + To create a table, you use the aptly named <command>CREATE |
| 81 | + TABLE</command> command. In this command you specify at least a |
82 | 82 | name for the new table, the names of the columns and the data type |
83 | 83 | of each column. For example: |
84 | 84 | <programlisting> |
@@ -302,18 +302,38 @@ DROP TABLE products; |
302 | 302 | </variablelist> |
303 | 303 |
|
304 | 304 | <para> |
305 | | - OIDs are 32-bit quantities and are assigned from a single cluster-wide |
306 | | - counter. In a large or long-lived database, it is possible for the |
307 | | - counter to wrap around. Hence, it is bad practice to assume that OIDs |
308 | | - are unique, unless you take steps to ensure that they are unique. |
309 | | - Recommended practice when using OIDs for row identification is to create |
310 | | - a unique constraint on the OID column of each table for which the OID will |
311 | | - be used. Never assume that OIDs are unique across tables; use the |
312 | | - combination of <structfield>tableoid</> and row OID if you need a |
313 | | - database-wide identifier. (Future releases of |
314 | | - <productname>PostgreSQL</productname> are likely to use a separate |
315 | | - OID counter for each table, so that <structfield>tableoid</> |
316 | | - <emphasis>must</> be included to arrive at a globally unique identifier.) |
| 305 | + OIDs are 32-bit quantities and are assigned from a single |
| 306 | + cluster-wide counter. In a large or long-lived database, it is |
| 307 | + possible for the counter to wrap around. Hence, it is bad |
| 308 | + practice to assume that OIDs are unique, unless you take steps to |
| 309 | + ensure that this is the case. If you need to identify the rows in |
| 310 | + a table, using a sequence generator is strongly recommended. |
| 311 | + However, OIDs can be used as well, provided that a few additional |
| 312 | + precautions are taken: |
| 313 | + |
| 314 | + <itemizedlist> |
| 315 | + <listitem> |
| 316 | + <para> |
| 317 | + A unique constraint should be created on the OID column of each |
| 318 | + table for which the OID will be used to identify rows. |
| 319 | + </para> |
| 320 | + </listitem> |
| 321 | + <listitem> |
| 322 | + <para> |
| 323 | + OIDs should never be assumed to be unique across tables; use |
| 324 | + the combination of <structfield>tableoid</> and row OID if you |
| 325 | + need a database-wide identifier. |
| 326 | + </para> |
| 327 | + </listitem> |
| 328 | + <listitem> |
| 329 | + <para> |
| 330 | + The tables in question should be created using <literal>WITH |
| 331 | + OIDS</literal> to ensure forward compatibility with future |
| 332 | + releases of <productname>PostgreSQL</productname> in which OIDs |
| 333 | + are not included in all tables by default. |
| 334 | + </para> |
| 335 | + </listitem> |
| 336 | + </itemizedlist> |
317 | 337 | </para> |
318 | 338 |
|
319 | 339 | <para> |
@@ -798,7 +818,7 @@ CREATE TABLE orders ( |
798 | 818 | ); |
799 | 819 | </programlisting> |
800 | 820 | Now it is impossible to create orders with |
801 | | - <literal>product_no</literal> entries that do not appear in the |
| 821 | + <structfield>product_no</structfield> entries that do not appear in the |
802 | 822 | products table. |
803 | 823 | </para> |
804 | 824 |
|
@@ -892,7 +912,7 @@ CREATE TABLE order_items ( |
892 | 912 |
|
893 | 913 | <para> |
894 | 914 | To illustrate this, let's implement the following policy on the |
895 | | - many-to-many relationship example above:When someone wants to |
| 915 | + many-to-many relationship example above:when someone wants to |
896 | 916 | remove a product that is still referenced by an order (via |
897 | 917 | <literal>order_items</literal>), we disallow it. If someone |
898 | 918 | removes an order, the order items are removed as well. |
|