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.
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 schema | Specify a table schema where the referenced table exists. |
Referenced table | Specify the referenced table. |
Fields | Specify 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 rule | Specify delete rule for the key. |
Update rule | Specify update rule for the key. |
Enabled | Specify either the constraint is enabled (for Oracle database). |
Deferrable | Specify either the constraint is deferrable (for Oracle and PostgreSQL databases). |
Deferred | Specify either the deferrable constraint is initially deferred (for Oracle and PostgreSQL databases). |
Action | Specify 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. |
Notes
- 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 detail.deal (id)
See also