1
- <!-- $Header: /cvsroot/pgsql/doc/src/sgml/ddl.sgml,v 1.5 2002/09/21 18:32:52 petere Exp $ -->
1
+ <!-- $Header: /cvsroot/pgsql/doc/src/sgml/ddl.sgml,v 1.6 2002/10/20 05:05:46 tgl Exp $ -->
2
2
3
3
<chapter id="ddl">
4
4
<title>Data Definition</title>
10
10
explaining how tables are created and modified and what features are
11
11
available to control what data is stored in the tables.
12
12
Subsequently, we discuss how tables can be organized into
13
- namespaces , and how privileges can be assigned to tables. Finally,
13
+ schemas , and how privileges can be assigned to tables. Finally,
14
14
we will briefly look at other features that affect the data storage,
15
15
such as views, functions, and triggers. Detailed information on
16
16
these topics is found in &cite-programmer;.
@@ -78,7 +78,7 @@ CREATE TABLE my_first_table (
78
78
<literal>second_column</literal> and the type <type>integer</type>.
79
79
The table and column names follow the identifier syntax explained
80
80
in <xref linkend="sql-syntax-identifiers">. The type names are
81
- also identifiers, but there are some exceptions. Note that the
81
+ usually also identifiers, but there are some exceptions. Note that the
82
82
column list is comma-separated and surrounded by parentheses.
83
83
</para>
84
84
@@ -101,7 +101,7 @@ CREATE TABLE products (
101
101
<tip>
102
102
<para>
103
103
When you create many interrelated tables it is wise to choose a
104
- consistent naming patter for the tables and columns. For
104
+ consistent naming pattern for the tables and columns. For
105
105
instance, there is a choice of using singular or plural nouns for
106
106
table names, both of which are favored by some theorist or other.
107
107
</para>
@@ -287,7 +287,7 @@ CREATE TABLE products (
287
287
</para>
288
288
289
289
<para>
290
- The default value may be a scalar expression, which well be
290
+ The default value may be a scalar expression, which will be
291
291
evaluated whenever the default value is inserted
292
292
(<emphasis>not</emphasis> when the table is created).
293
293
</para>
@@ -618,7 +618,8 @@ CREATE TABLE example (
618
618
619
619
<para>
620
620
A foreign key constraint specifies that the values in a column (or
621
- a group of columns) must match the values in some other column.
621
+ a group of columns) must match the values appearing in some row
622
+ of another table.
622
623
We say this maintains the <firstterm>referential
623
624
integrity</firstterm> between two related tables.
624
625
</para>
@@ -758,7 +759,7 @@ CREATE TABLE order_items (
758
759
<para>
759
760
Restricting and cascading deletes are the two most common options.
760
761
<literal>RESTRICT</literal> can also be written as <literal>NO
761
- ACTON </literal> and it's also the default if you don't specify
762
+ ACTION </literal> and it's also the default if you don't specify
762
763
anything. There are two other options for what should happen with
763
764
the foreign key columns when a primary key is deleted:
764
765
<literal>SET NULL</literal> and <literal>SET DEFAULT</literal>.
@@ -981,7 +982,7 @@ SET SQL_Inheritance TO OFF;
981
982
<para>Add columns,</para>
982
983
</listitem>
983
984
<listitem>
984
- <para>Remove a column ,</para>
985
+ <para>Remove columns ,</para>
985
986
</listitem>
986
987
<listitem>
987
988
<para>Add constraints,</para>
@@ -993,10 +994,10 @@ SET SQL_Inheritance TO OFF;
993
994
<para>Change default values,</para>
994
995
</listitem>
995
996
<listitem>
996
- <para>Rename a column ,</para>
997
+ <para>Rename columns ,</para>
997
998
</listitem>
998
999
<listitem>
999
- <para>Rename the table .</para>
1000
+ <para>Rename tables .</para>
1000
1001
</listitem>
1001
1002
</itemizedlist>
1002
1003
@@ -1270,7 +1271,7 @@ REVOKE ALL ON accounts FROM PUBLIC;
1270
1271
</itemizedlist>
1271
1272
1272
1273
Schemas are analogous to directories at the operating system level,
1273
- but schemas cannot be nested.
1274
+ except that schemas cannot be nested.
1274
1275
</para>
1275
1276
1276
1277
<sect2 id="ddl-schemas-create">
@@ -1341,7 +1342,7 @@ DROP SCHEMA myschema CASCADE;
1341
1342
(since this is one of the ways to restrict the activities of your
1342
1343
users to well-defined namespaces). The syntax for that is:
1343
1344
<programlisting>
1344
- CREATE SCHEMA <replaceable>schemaname</replaceable> AUTHORIZATON <replaceable>username</replaceable>;
1345
+ CREATE SCHEMA <replaceable>schemaname</replaceable> AUTHORIZATION <replaceable>username</replaceable>;
1345
1346
</programlisting>
1346
1347
You can even omit the schema name, in which case the schema name
1347
1348
will be the same as the user name. See <xref
@@ -1359,9 +1360,9 @@ CREATE SCHEMA <replaceable>schemaname</replaceable> AUTHORIZATON <replaceable>us
1359
1360
1360
1361
<para>
1361
1362
In the previous sections we created tables without specifying any
1362
- schema names. Those tables (and other objects) are automatically
1363
- put into a schema named <quote>public</quote>. Every new database
1364
- contains such a schema. Thus, the following are equivalent:
1363
+ schema names. By default, such tables (and other objects) are
1364
+ automatically put into a schema named <quote>public</quote>. Every new
1365
+ database contains such a schema. Thus, the following are equivalent:
1365
1366
<programlisting>
1366
1367
CREATE TABLE products ( ... );
1367
1368
</programlisting>
@@ -1550,15 +1551,15 @@ REVOKE CREATE ON public FROM PUBLIC;
1550
1551
1551
1552
<para>
1552
1553
Schemas can be used to organize your data in many ways. There are
1553
- a few usage patterns are recommended and are easily supported by
1554
+ a few usage patterns that are recommended and are easily supported by
1554
1555
the default configuration:
1555
1556
<itemizedlist>
1556
1557
<listitem>
1557
1558
<para>
1558
1559
If you do not create any schemas then all users access the
1559
1560
public schema implicitly. This simulates the situation where
1560
1561
schemas are not available at all. This setup is mainly
1561
- recommended when there is only a single user or few cooperating
1562
+ recommended when there is only a single user or a few cooperating
1562
1563
users in a database. This setup also allows smooth transition
1563
1564
from the non-schema-aware world.
1564
1565
</para>
@@ -1586,7 +1587,7 @@ REVOKE CREATE ON public FROM PUBLIC;
1586
1587
additional functions provided by third parties, etc.), put them
1587
1588
into separate schemas. Remember to grant appropriate
1588
1589
privileges to allow the other users to access them. Users can
1589
- then refer to these additional object by qualifying the names
1590
+ then refer to these additional objects by qualifying the names
1590
1591
with a schema name, or they can put the additional schemas into
1591
1592
their path, as they choose.
1592
1593
</para>
@@ -1690,9 +1691,10 @@ ERROR: Cannot drop table products because other objects depend on it
1690
1691
<screen>
1691
1692
DROP TABLE products CASCADE;
1692
1693
</screen>
1693
- and all the dependent objects will be removed. Actually, this
1694
+ and all the dependent objects will be removed. In this case, it
1694
1695
doesn't remove the orders table, it only removes the foreign key
1695
- constraint.
1696
+ constraint. (If you want to check what DROP ... CASCADE will do,
1697
+ run DROP without CASCADE and read the NOTICEs.)
1696
1698
</para>
1697
1699
1698
1700
<para>
@@ -1709,7 +1711,8 @@ DROP TABLE products CASCADE;
1709
1711
According to the SQL standard, specifying either
1710
1712
<literal>RESTRICT</literal> or <literal>CASCADE</literal> is
1711
1713
required. No database system actually implements it that way, but
1712
- the defaults might be different.
1714
+ whether the default behavior is <literal>RESTRICT</literal> or
1715
+ <literal>CASCADE</literal> varies across systems.
1713
1716
</para>
1714
1717
</note>
1715
1718
@@ -1718,7 +1721,8 @@ DROP TABLE products CASCADE;
1718
1721
Foreign key constraint dependencies and serial column dependencies
1719
1722
from <productname>PostgreSQL</productname> versions prior to 7.3
1720
1723
are <emphasis>not</emphasis> maintained or created during the
1721
- upgrade process. All other dependency types survive the upgrade.
1724
+ upgrade process. All other dependency types will be properly
1725
+ created during an upgrade.
1722
1726
</para>
1723
1727
</note>
1724
1728
</sect1>
0 commit comments