From 3d56fb7598054ab9fc2ddbc3b53cc5f5947afbef Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Wed, 30 May 2001 13:01:08 +0000 Subject: [PATCH] This is a docs patch to go with my DROP CONSTRAINT patch. Christopher Kings --- doc/src/sgml/ref/alter_table.sgml | 63 ++++++++++++++++--------------- 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/doc/src/sgml/ref/alter_table.sgml b/doc/src/sgml/ref/alter_table.sgml index 5649890bf8..87252f7467 100644 --- a/doc/src/sgml/ref/alter_table.sgml +++ b/doc/src/sgml/ref/alter_table.sgml @@ -1,5 +1,5 @@ @@ -38,6 +38,8 @@ ALTER TABLE table RENAME TO newtable ALTER TABLE table ADD table constraint definition +ALTER TABLE [ ONLY ] table + DROP CONSTRAINT constraint { RESTRICT | CASCADE } ALTER TABLE table OWNER TO new owner @@ -177,6 +179,8 @@ ALTER TABLE table The ADD table constraint definition clause adds a new constraint to the table using the same syntax as . + The DROP CONSTRAINT constraint clause + drops all CHECK constraints on the table (and its children) that match constraint. The OWNER clause changes the owner of the table to the user new user. @@ -208,11 +212,31 @@ ALTER TABLE table In the current implementation, only FOREIGN KEY and CHECK constraints can - be added to a table. To create or remove a unique constraint, create + be added to a table. To create a unique constraint, create a unique index (see ). + + Currently only CHECK constraints can be dropped from a table. The RESTRICT + keyword is required, although dependencies are not checked. The CASCADE + option is unsupported. To remove a PRIMARY or UNIQUE constraint, drop the + relevant index using the command. + To remove FOREIGN KEY constraints you need to recreate + and reload the table, using other parameters to the + + command. + + + For example, to drop all constraints on a table distributors: + +CREATE TABLE temp AS SELECT * FROM distributors; +DROP TABLE distributors; +CREATE TABLE distributors AS SELECT * FROM temp; +DROP TABLE temp; + + + You must own the table in order to change it. Changing any part of the schema of a system @@ -260,6 +284,13 @@ ALTER TABLE distributors ADD CONSTRAINT zipchk CHECK (char_length(zipcode) = 5) + + To remove a check constraint from a table and all its children: + +ALTER TABLE distributors DROP CONSTRAINT zipchk + + + To add a foreign key constraint to a table: @@ -289,34 +320,6 @@ ALTER TABLE distributors ADD CONSTRAINT distfk FOREIGN KEY (address) REFERENCES statement which are not yet directly supported by Postgres: - - - -ALTER TABLE table DROP CONSTRAINT constraint { RESTRICT | CASCADE } - - - - - Removes a table constraint (such as a check constraint, - unique constraint, or foreign key constraint). To - remove a unique constraint, drop a unique index. - To remove other kinds of constraints you need to recreate - and reload the table, using other parameters to the - - command. - - - For example, to drop any constraints on a table distributors: - -CREATE TABLE temp AS SELECT * FROM distributors; -DROP TABLE distributors; -CREATE TABLE distributors AS SELECT * FROM temp; -DROP TABLE temp; - - - - -