Creating Foreign Key from GUI

To add a foreign key to a table table, open that table, switch to the Foreign Keys page of the Table window, and click Add button.

Creating a foreign key in Database Tour

After you click OK button, you will be asking for the constraint name. You can just confirm the application generated name if it suits you.

Creating Foreign Key Options

Referenced schemaSpecify a table schema where the referenced table exists.
Referenced tableSpecify the referenced table.
FieldsSpecify the field mappings between fields / columns in a source table and fields / columns in a referenced table. To add a mapping, click Add button and specify a field from the left (source) side and the corresponding field from the right (referenced) side. To delete a mapping, select its line in the grid and click Delete button. To reorder mappings (if their count is more than one), use Up and Down buttons.
Delete ruleSpecify delete rule for the key.
Update ruleSpecify update rule for the key.
EnabledSpecify either the constraint is enabled (for Oracle database).
DeferrableSpecify either the constraint is deferrable (for Oracle and PostgreSQL databases).
DeferredSpecify either the deferrable constraint is initially deferred (for Oracle and PostgreSQL databases).
ActionSpecify either to add the foreign key immediately or generate SQL code instead. In latter case, you are able to modify the generated SQL code before applying the command.


  1. Working with foreign keys through the interface is currently supported only for Oracle, PostgreSQL, SQL Server, Firebird, Interbase, MySQL databases.

Creating Foreign Key by SQL

Advanced users can also create a foreign key by executing SQL query like this (read your database documentation for details):

ALTER TABLE detail.invoice ADD CONSTRAINT invoice_deal_fkey FOREIGN KEY (deal_id) REFERENCES (id)

See also

 Adding or Modifying Table Field

 Adding Table Index

 Adding Table Constraint

 Adding Table Partition

 Viewing and Editing Table Structure