Ask a Question
Report a Bug
This page in other versions:
Warning: This documentation is for a pre-release version of pgAdmin 4
Use the Foreign key dialog to specify the behavior of a foreign key
constraint. A foreign key constraint maintains referential integrity between
two tables. A foreign key constraint cannot be defined between a temporary
table and a permanent table.
The Foreign key dialog organizes the development of a foreign key constraint
through the following dialog tabs: General, Definition, Columns, and
Action. The SQL tab displays the SQL code generated by dialog selections.
Use the fields in the General tab to identify the foreign key constraint:
Click the Definition tab to continue.
Use the fields in the Definition tab to define the foreign key constraint:
Move the Deferrable? switch to the Yes position to specify the timing of
the constraint is deferrable and can be postponed until the end of the
statement. The default is No.
If enabled, move the Deferred? switch to the Yes position to specify the
timing of the constraint is deferred to the end of the statement. The default
Move the Match type switch specify the type of matching that is enforced by
Select Full to indicate that all columns of a multicolumn foreign key
must be null if any column is null; if all columns are null, the row is
not required to have a match in the referenced table.
Select Simple to specify that a single foreign key column may be null;
if any column is null, the row is not required to have a match in the
Move the Validated switch to the Yes position to instruct the server to
validate the existing table content (against a foreign key or check
constraint) when you save modifications to this dialog.
Move the Auto FK Index switch to the No position to disable the automatic
The field next to Covering Index generates the name of an index if the Auto
FK Index switch is in the Yes position; or, this field is disabled.
Click the Columns tab to continue.
Use the fields in the Columns tab to specify one or more reference column(s).
A Foreign Key constraint requires that one or more columns of a table must only
contain values that match values in the referenced column(s) of a row of a
Click the Add icon (+) to add a column to the list; repeat the steps above and
click the Add icon (+) to add additional columns. To discard an entry, click
the trash icon to the left of the entry and confirm deletion in the Delete Row
Click the Action tab to continue.
Use the drop-down listboxes on the Action tab to specify behavior related to
the foreign key constraint that will be performed when data within the table is
updated or deleted:
The supported actions are:
Click the SQL tab to continue.
Your entries in the Foreign key dialog generate a SQL command (see an example
below). Use the SQL tab for review; revisit or switch tabs to make any changes
to the SQL command.
The following is an example of the sql command generated by user selections in
the Foreign key dialog:
The example shown demonstrates creating a foreign key constraint named
territory_fkey that matches values in the distributors table territory
column with those of the sales_territories table region column.