Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3d56fb7

Browse files
committed
This is a docs patch to go with my DROP CONSTRAINT patch.
Christopher Kings
1 parent7160c86 commit3d56fb7

File tree

1 file changed

+33
-30
lines changed

1 file changed

+33
-30
lines changed

‎doc/src/sgml/ref/alter_table.sgml

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/alter_table.sgml,v 1.24 2001/05/09 13:27:15 momjian Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/alter_table.sgml,v 1.25 2001/05/30 13:01:08 momjian Exp $
33
Postgres documentation
44
-->
55

@@ -38,6 +38,8 @@ ALTER TABLE <replaceable class="PARAMETER">table</replaceable>
3838
RENAME TO <replaceable class="PARAMETER">newtable</replaceable>
3939
ALTER TABLE <replaceable class="PARAMETER">table</replaceable>
4040
ADD <replaceable class="PARAMETER">table constraint definition</replaceable>
41+
ALTER TABLE [ ONLY ] <replaceable class="PARAMETER">table</replaceable>
42+
DROP CONSTRAINT <replaceable class="PARAMETER">constraint</replaceable> { RESTRICT | CASCADE }
4143
ALTER TABLE <replaceable class="PARAMETER">table</replaceable>
4244
OWNER TO <replaceable class="PARAMETER">new owner</replaceable>
4345
</synopsis>
@@ -177,6 +179,8 @@ ALTER TABLE <replaceable class="PARAMETER">table</replaceable>
177179
The ADD <replaceable class="PARAMETER">table constraint definition</replaceable> clause
178180
adds a new constraint to the table using the same syntax as <xref
179181
linkend="SQL-CREATETABLE" endterm="SQL-CREATETABLE-title">.
182+
The DROP CONSTRAINT <replaceable class="PARAMETER">constraint</replaceable> clause
183+
drops all CHECK constraints on the table (and its children) that match <replaceable class="PARAMETER">constraint</replaceable>.
180184
The OWNER clause changes the owner of the table to the user <replaceable class="PARAMETER">
181185
new user</replaceable>.
182186
</para>
@@ -208,11 +212,31 @@ ALTER TABLE <replaceable class="PARAMETER">table</replaceable>
208212

209213
<para>
210214
In the current implementation, only FOREIGN KEY and CHECK constraints can
211-
be added to a table. To createor removea unique constraint, create
215+
be added to a table. To create a unique constraint, create
212216
a unique index (see <xref linkend="SQL-CREATEINDEX"
213217
endterm="SQL-CREATEINDEX-title">).
214218
</para>
215219

220+
<para>
221+
Currently only CHECK constraints can be dropped from a table. The RESTRICT
222+
keyword is required, although dependencies are not checked. The CASCADE
223+
option is unsupported. To remove a PRIMARY or UNIQUE constraint, drop the
224+
relevant index using the <xref linkend="SQL-DROPINDEX" endterm="SQL-DROPINDEX-TITLE"> command.
225+
To remove FOREIGN KEY constraints you need to recreate
226+
and reload the table, using other parameters to the
227+
<xref linkend="SQL-CREATETABLE" endterm="SQL-CREATETABLE-title">
228+
command.
229+
</para>
230+
<para>
231+
For example, to drop all constraints on a table <literal>distributors</literal>:
232+
<programlisting>
233+
CREATE TABLE temp AS SELECT * FROM distributors;
234+
DROP TABLE distributors;
235+
CREATE TABLE distributors AS SELECT * FROM temp;
236+
DROP TABLE temp;
237+
</programlisting>
238+
</para>
239+
216240
<para>
217241
You must own the table in order to change it.
218242
Changing any part of the schema of a system
@@ -260,6 +284,13 @@ ALTER TABLE distributors ADD CONSTRAINT zipchk CHECK (char_length(zipcode) = 5)
260284
</programlisting>
261285
</para>
262286

287+
<para>
288+
To remove a check constraint from a table and all its children:
289+
<programlisting>
290+
ALTER TABLE distributors DROP CONSTRAINT zipchk
291+
</programlisting>
292+
</para>
293+
263294
<para>
264295
To add a foreign key constraint to a table:
265296
<programlisting>
@@ -289,34 +320,6 @@ ALTER TABLE distributors ADD CONSTRAINT distfk FOREIGN KEY (address) REFERENCES
289320
statement which are not yet directly supported by <productname>Postgres</productname>:
290321

291322
<variablelist>
292-
<varlistentry>
293-
<term>
294-
<synopsis>
295-
ALTER TABLE <replaceable class="PARAMETER">table</replaceable> DROP CONSTRAINT <replaceable class="PARAMETER">constraint</replaceable> { RESTRICT | CASCADE }
296-
</synopsis>
297-
</term>
298-
<listitem>
299-
<para>
300-
Removes a table constraint (such as a check constraint,
301-
unique constraint, or foreign key constraint). To
302-
remove a unique constraint, drop a unique index.
303-
To remove other kinds of constraints you need to recreate
304-
and reload the table, using other parameters to the
305-
<xref linkend="SQL-CREATETABLE" endterm="SQL-CREATETABLE-title">
306-
command.
307-
</para>
308-
<para>
309-
For example, to drop any constraints on a table <literal>distributors</literal>:
310-
<programlisting>
311-
CREATE TABLE temp AS SELECT * FROM distributors;
312-
DROP TABLE distributors;
313-
CREATE TABLE distributors AS SELECT * FROM temp;
314-
DROP TABLE temp;
315-
</programlisting>
316-
</para>
317-
</listitem>
318-
</varlistentry>
319-
320323
<varlistentry>
321324
<term>
322325
<synopsis>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp