|
1 | 1 | <!-- |
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 $ |
3 | 3 | Postgres documentation |
4 | 4 | --> |
5 | 5 |
|
@@ -38,6 +38,8 @@ ALTER TABLE <replaceable class="PARAMETER">table</replaceable> |
38 | 38 | RENAME TO <replaceable class="PARAMETER">newtable</replaceable> |
39 | 39 | ALTER TABLE <replaceable class="PARAMETER">table</replaceable> |
40 | 40 | 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 } |
41 | 43 | ALTER TABLE <replaceable class="PARAMETER">table</replaceable> |
42 | 44 | OWNER TO <replaceable class="PARAMETER">new owner</replaceable> |
43 | 45 | </synopsis> |
@@ -177,6 +179,8 @@ ALTER TABLE <replaceable class="PARAMETER">table</replaceable> |
177 | 179 | The ADD <replaceable class="PARAMETER">table constraint definition</replaceable> clause |
178 | 180 | adds a new constraint to the table using the same syntax as <xref |
179 | 181 | 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>. |
180 | 184 | The OWNER clause changes the owner of the table to the user <replaceable class="PARAMETER"> |
181 | 185 | new user</replaceable>. |
182 | 186 | </para> |
@@ -208,11 +212,31 @@ ALTER TABLE <replaceable class="PARAMETER">table</replaceable> |
208 | 212 |
|
209 | 213 | <para> |
210 | 214 | In the current implementation, only FOREIGN KEY and CHECK constraints can |
211 | | - be added to a table. To create or remove a unique constraint, create |
| 215 | + be added to a table. To create a unique constraint, create |
212 | 216 | a unique index (see <xref linkend="SQL-CREATEINDEX" |
213 | 217 | endterm="SQL-CREATEINDEX-title">). |
214 | 218 | </para> |
215 | 219 |
|
| 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 | + |
216 | 240 | <para> |
217 | 241 | You must own the table in order to change it. |
218 | 242 | Changing any part of the schema of a system |
@@ -260,6 +284,13 @@ ALTER TABLE distributors ADD CONSTRAINT zipchk CHECK (char_length(zipcode) = 5) |
260 | 284 | </programlisting> |
261 | 285 | </para> |
262 | 286 |
|
| 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 | + |
263 | 294 | <para> |
264 | 295 | To add a foreign key constraint to a table: |
265 | 296 | <programlisting> |
@@ -289,34 +320,6 @@ ALTER TABLE distributors ADD CONSTRAINT distfk FOREIGN KEY (address) REFERENCES |
289 | 320 | statement which are not yet directly supported by <productname>Postgres</productname>: |
290 | 321 |
|
291 | 322 | <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 | | - |
320 | 323 | <varlistentry> |
321 | 324 | <term> |
322 | 325 | <synopsis> |
|
0 commit comments