- class="parameter">constraint } [, ...]
+ class="parameter">constraint | REFERENCES
+ referenced table
+ (referenced column)
+ [ MATCH match type ]
+ [ ON DELETE action ]
+ [ ON UPDATE action ]
+ [ [ NOT ] DEFERRABLE ]
+ [ INITIALLY check time ] }
+ [, ...]
Only one PRIMARY KEY can be specified for a table.
-
+
Notes
+
+
+
+ 2000-02-04
+
+
+ REFERENCES Constraint
+
+
+[ CONSTRAINT name ] REFERENCES
+referenced table [ ( referenced column ) ]
+[ MATCH matchtype ]
+[ ON DELETE action ]
+[ ON UPDATE action ]
+[ [ NOT ] DEFERRABLE ]
+[ INITIALLY check time ]
+
+ The REFERENCES constraint specifies a rule that a column
+ value is checked against the values of another column.
+ REFERENCES can also be specified as part of
+ a FOREIGN KEY table constraint.
+
+
+
+
Inputs
+
+
+ CONSTRAINT name
+
+ An arbitrary name for the constraint.
+
+
+
+
+ referenced table
+
+ The table that contains the data to check against.
+
+
+
+
+ referenced column
+
+ The column in the referenced table
+ to check the data against. If this is not specified, the PRIMARY KEY of the
+ referenced table is used.
+
+
+
+
+ MATCH matchtype
+
+ The type of comparison to do between the table data. There are three
+ types of matching, MATCH FULL, MATCH PARTIAL, and the unspecified match type
+ used if no match type is specified.
+
+
+
+
+ ON DELETE action
+
+ The action to do when a referenced row in the referenced table is being
+ deleted. There are the following actions.
+
+
+ CASCADE
+
+ Delete any rows referencing the deleted row.
+
+
+
+
+ RESTRICT
+
+ Disallow deletion of rows being referenced.
+
+
+
+
+ SET NULL
+
+ Set the referencing column values to NULL.
+
+
+
+
+ SET DEFAULT
+
+ Set the referencing column values to their default value.
+
+
+
+
+ NO ACTION
+
+ Do nothing.
+
+
+
+
+
+
+
+
+ ON UPDATE action
+
+ The action to do when a referenced column in the referenced table is being
+ updated to a new value. If the row is updated, but the referenced column
+ is not changed, no action is done. There are the following actions.
+
+
+ CASCADE
+
+ Update the value of the referencing column to the new value of the
+ referenced column.
+
+
+
+
+ RESTRICT
+
+ Disallow update of row being referenced.
+
+
+
+
+ SET NULL
+
+ Set the referencing column values to NULL.
+
+
+
+
+ SET DEFAULT
+
+ Set the referencing column values to their default value.
+
+
+
+
+ NO ACTION
+
+ Do nothing.
+
+
+
+
+
+
+
+
+ [ NOT ] DEFERRABLE
+
+ Tells the trigger manager whether this constraint may be
+ deferred to the end of transaction.
+
+
+
+
+ INITIALLY check time
+
+ check time has two possible values
+ which specify the default time to check the constraint.
+
+
+ DEFERRED
+ Check this constraint at the end of the transaction.
+
+
+
+ IMMEDIATE
+ Check this constraint after each statement.
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 2000-02-04
+
+
+ Outputs
+
+
+
+ status
+
+
+
+
+ERROR: name referential integrity violation - key referenced from
+table not found in referenced table
+
+
+ This error occurs at runtime if one tries to insert a value
+ into a column which does not have a matching column in the
+ referenced table.
+
+
+
+
+
+
+
+
+
+
+
+
+
Description
+ The REFERENCES column constraint specifies that a column of a
+ table must only contain values which match against values
+ in a referenced column of a referenced table.
+
+ A value added to this column are matched against the
+ values of the referenced table and referenced column using
+ the given match type.
+ In addition, when the referenced column data is changed,
+ actions are run upon this column's matching data.
+
+
+
+
+
+ 1998-09-11
+
+
+ Notes
+
+ Currently
Postgres only supports
+ MATCH FULL and an unspecified MATCH type.
+ In addition, the referenced columns are supposed to be
+ the columns of a UNIQUE constraint in the referenced table,
+ however
Postgres does not
+ enforce this.
+
+
[ CONSTRAINT name ] { PRIMARY KEY | UNIQUE } ( column [, ...] )
[ CONSTRAINT name ] CHECK ( constraint )
+[ CONSTRAINT name ] FOREIGN KEY ( column [, ...] )
+ REFERENCES referenced table
+ (referenced column [, ...] )
+ [ MATCH ]
+ [ ON DELETE action ]
+ [ ON UPDATE action ]
+ [ [ NOT ] DEFERRABLE ]
+ [ INITIALLY check time ]
information.
+
+
+
+ 2000-02-04
+
+
+ REFERENCES Constraint
+
+
+[ CONSTRAINT name ]
+FOREIGN KEY ( column [, ...] ) REFERENCES
+referenced table [ ( referenced column [, ...] ) ]
+[ MATCH matchtype ]
+[ ON DELETE action ]
+[ ON UPDATE action ]
+[ [ NOT ] DEFERRABLE ]
+[ INITIALLY check time ]
+
+ The REFERENCES constraint specifies a rule that a column
+ value is checked against the values of another column.
+ REFERENCES can also be specified as part of
+ a FOREIGN KEY table constraint.
+
+
+
+
Inputs
+
+
+ CONSTRAINT name
+
+ An arbitrary name for the constraint.
+
+
+
+
+ column [, ...]
+
+ The names of one or more columns in the table.
+
+
+
+
+ referenced table
+
+ The table that contains the data to check against.
+
+
+
+
+ referenced column [, ...]
+
+ One or more column in the referenced table
+ to check the data against. If this is not specified, the PRIMARY KEY of the
+ referenced table is used.
+
+
+
+
+ MATCH matchtype
+
+ The type of comparison to do between the table data. There are three
+ types of matching, MATCH FULL, MATCH PARTIAL, and the unspecified match type
+ used if no match type is specified.
+
+
+
+
+ ON DELETE action
+
+ The action to do when a referenced row in the referenced table is being
+ deleted. There are the following actions.
+
+
+ CASCADE
+
+ Delete any rows referencing the deleted row.
+
+
+
+
+ RESTRICT
+
+ Disallow deletion of rows being referenced.
+
+
+
+
+ SET NULL
+
+ Set the referencing column values to NULL.
+
+
+
+
+ SET DEFAULT
+
+ Set the referencing column values to their default value.
+
+
+
+
+ NO ACTION
+
+ Do nothing.
+
+
+
+
+
+
+
+
+ ON UPDATE action
+
+ The action to do when a referenced column in the referenced table is being
+ updated to a new value. If the row is updated, but the referenced column
+ is not changed, no action is done. There are the following actions.
+
+
+ CASCADE
+
+ Update the value of the referencing column to the new value of the
+ referenced column.
+
+
+
+
+ RESTRICT
+
+ Disallow update of row being referenced.
+
+
+
+
+ SET NULL
+
+ Set the referencing column values to NULL.
+
+
+
+
+ SET DEFAULT
+
+ Set the referencing column values to their default value.
+
+
+
+
+ NO ACTION
+
+ Do nothing.
+
+
+
+
+
+
+
+
+ [ NOT ] DEFERRABLE
+
+ Tells the trigger manager whether this constraint may be
+ deferred to the end of transaction.
+
+
+
+
+ INITIALLY check time
+
+ check time has two possible values
+ which specify the default time to check the constraint.
+
+
+ DEFERRED
+ Check this constraint at the end of the transaction.
+
+
+
+ IMMEDIATE
+ Check this constraint after each statement.
+
+
+
+
+
+
+
+
+
+
+
+ 2000-02-04
+
+
+ Outputs
+
+
+
+ status
+
+
+
+
+ERROR: name referential integrity violation - key referenced from
+table not found in referenced table
+
+
+ This error occurs at runtime if one tries to insert a value
+ into a column which does not have a matching column in the
+ referenced table.
+
+
+
+
+
+
+
+
+
+
+
+
Description
+ The FOREIGN KEY constraint specifies a rule that a group of one
+ or more distinct columns of a table are related to a group
+ of distinct columns in the referenced table.
+
+
+ The FOREIGN KEY table constraint is similar to that for column constraints,
+ with the additional capability of encompassing multiple columns.
+
+ Refer to the section on the FOREIGN KEY column constraint for more
+ information.
+
+
+