-
+
Foreign key match type
+ |
+ conislocal
+ bool
+
+
+ This constraint is defined locally in the relation. Note that a
+ constraint can be locally defined and inherited simultaneously
+
+
+
+ |
+ coninhcount
+ int4
+
+
+ The number of direct ancestors this constraint has. A constraint with
+ a nonzero number of ancestors cannot be dropped nor renamed
+
+
+
|
conkey
int2[]
-
+
Data Definition
A parent table cannot be dropped while any of its children remain. Neither
- can columns of child tables be dropped or altered if they are inherited
+ can columns or check constraints of child tables be dropped or altered
+ if they are inherited
from any parent tables. If you wish to remove a table and all of its
descendants, one easy way is to drop the parent table with the
CASCADE option.
will
propagate any changes in column data definitions and check
constraints down the inheritance hierarchy. Again, dropping
- columns or constraints on parent tables is only possible when using
+ columns that are depended on by other tables is only possible when using
the CASCADE option. ALTER
TABLE follows the same rules for duplicate column merging
and rejection that apply during CREATE TABLE.
The TRIGGER>, CLUSTER>, OWNER>,
and TABLESPACE> actions never recurse to descendant tables;
that is, they always act as though ONLY> were specified.
- Adding a constraint can recurse only for CHECK> constraints.
+ Adding a constraint can recurse only for CHECK> constraints,
+ and is required to do so for such constraints.
- To add a check constraint to a table:
+ To add a check constraint to a table and all its children:
ALTER TABLE distributors ADD CONSTRAINT zipchk CHECK (char_length(zipcode) = 5);
+ To remove a check constraint from a table only:
+ALTER TABLE ONLY distributors DROP CONSTRAINT zipchk;
+
+ (The check constraint remains in place for any child tables.)
+
+
To add a foreign key constraint to a table:
the new table. If the column name list of the new table
contains a column name that is also inherited, the data type must
likewise match the inherited column(s), and the column
- definitions are merged into one. However, inherited and new
- column declarations of the same name need not specify identical
- constraints: all constraints provided from any declaration are
- merged together and all are applied to the new table. If the
+ definitions are merged into one. If the
new table explicitly specifies a default value for the column,
this default overrides any defaults from inherited declarations
of the column. Otherwise, any parents that specify default
values for the column must all specify the same default, or an
error will be reported.
+
+ CHECK> constraints are merged in essentially the same way as
+ columns: if multiple parent tables and/or the new table definition
+ contain identically-named CHECK> constraints, these
+ constraints must all have the same check expression, or an error will be
+ reported. Constraints having the same name and expression will
+ be merged into one copy. Notice that an unnamed CHECK>
+ constraint in the new table will never be merged, since a unique name
+ will always be chosen for it.
+
+