1
1
<!--
2
- $Header: /cvsroot/pgsql/doc/src/sgml/ref/alter_table.sgml,v 1.11 2000/03/27 17: 14:42 thomas Exp $
2
+ $Header: /cvsroot/pgsql/doc/src/sgml/ref/alter_table.sgml,v 1.12 2000/04/11 14:43:54 momjian Exp $
3
3
Postgres documentation
4
4
-->
5
5
@@ -34,6 +34,8 @@ ALTER TABLE <replaceable class="PARAMETER">table</replaceable> [ * ]
34
34
class="PARAMETER">newcolumn</replaceable>
35
35
ALTER TABLE <replaceable class="PARAMETER">table</replaceable>
36
36
RENAME TO <replaceable class="PARAMETER">newtable</replaceable>
37
+ ALTER TABLE <replaceable class="PARAMETER">table</replaceable>
38
+ ADD <replaceable class="PARAMETER">table constraint definition</replaceable>
37
39
</synopsis>
38
40
39
41
<refsect2 id="R2-SQL-ALTERTABLE-1">
@@ -89,6 +91,15 @@ ALTER TABLE <replaceable class="PARAMETER">table</replaceable>
89
91
</para>
90
92
</listitem>
91
93
</varlistentry>
94
+
95
+ <varlistentry>
96
+ <term><replaceable class="PARAMETER"> table constraint definition </replaceable></term>
97
+ <listitem>
98
+ <para>
99
+ New table constraint for the table
100
+ </para>
101
+ </listitem>
102
+ </varlistentry>
92
103
</variablelist>
93
104
</para>
94
105
</refsect2>
@@ -144,6 +155,9 @@ ALTER TABLE <replaceable class="PARAMETER">table</replaceable>
144
155
the affected table. Thus, the table or column will
145
156
remain of the same type and size after this command is
146
157
executed.
158
+ The ADD <replaceable class="PARAMETER">table constraint definition</replaceable> clause
159
+ adds a new constraint to the table using the same syntax as <xref
160
+ linkend="SQL-CREATETABLE" endterm="SQL-CREATETABLE-title">.
147
161
</para>
148
162
149
163
<para>
@@ -188,6 +202,16 @@ SELECT <replaceable>NewColumn</replaceable> FROM <replaceable>SuperClass</replac
188
202
endterm="sql-update-title">.)
189
203
</para>
190
204
205
+ <para>
206
+ In the current implementation, only FOREIGN KEY constraints can
207
+ be added to a table. To create or remove a unique constraint, create
208
+ a unique index (see <xref linkend="SQL-CREATEINDEX"
209
+ endterm="SQL-CREATEINDEX-title">). To add check constraints
210
+ you need to recreate and reload the table, using other
211
+ parameters to the <xref linkend="SQL-CREATETABLE"
212
+ endterm="SQL-CREATETABLE-title"> command.
213
+ </para>
214
+
191
215
<para>
192
216
You must own the class in order to change its schema.
193
217
Renaming any part of the schema of a system
@@ -227,6 +251,13 @@ ALTER TABLE distributors RENAME COLUMN address TO city;
227
251
ALTER TABLE distributors RENAME TO suppliers;
228
252
</programlisting>
229
253
</para>
254
+
255
+ <para>
256
+ To add a foreign key constraint to a table:
257
+ <programlisting>
258
+ ALTER TABLE distributors ADD CONSTRAINT distfk FOREIGN KEY (address) REFERENCES addresses(address) MATCH FULL
259
+ </programlisting>
260
+ </para>
230
261
</refsect1>
231
262
232
263
<refsect1 id="R1-SQL-ALTERTABLE-3">
@@ -253,17 +284,15 @@ ALTER TABLE distributors RENAME TO suppliers;
253
284
<varlistentry>
254
285
<term>
255
286
<synopsis>
256
- ALTER TABLE <replaceable class="PARAMETER">table</replaceable> ADD <replaceable class="PARAMETER">table constraint definition</replaceable>
257
287
ALTER TABLE <replaceable class="PARAMETER">table</replaceable> DROP CONSTRAINT <replaceable class="PARAMETER">constraint</replaceable> { RESTRICT | CASCADE }
258
288
</synopsis>
259
289
</term>
260
290
<listitem>
261
291
<para>
262
- Adds or removes a table constraint (such as a check constraint,
263
- unique constraint, or foreign key constraint). To create
264
- or remove a unique constraint, create or drop a unique index,
265
- respectively (see <xref linkend="SQL-CREATEINDEX" endterm="SQL-CREATEINDEX-title">).
266
- To change other kinds of constraints you need to recreate
292
+ Removes a table constraint (such as a check constraint,
293
+ unique constraint, or foreign key constraint). To
294
+ remove a unique constraint, drop a unique index,
295
+ To remove other kinds of constraints you need to recreate
267
296
and reload the table, using other parameters to the
268
297
<xref linkend="SQL-CREATETABLE" endterm="SQL-CREATETABLE-title">
269
298
command.
0 commit comments