Add foreign keys

A foreign key constraint specifies that values in one table must also appear in another table. Foreign keys that are part of the database structure are displayed, but foreign keys can also be added.

Right-click on the table in the meta-schema diagram to which you want to add a foreign key. Select Add Foreign Key.

Figure: Add Foreign Key dialog


This figure is a screenshot of the Add Foreign Key dialog.
Name
Name of foreign key, a suggested name is provided. This name will display in the Structure and Properties views.
Table
Select the table that contains the foreign key.
Referenced table
Select the table that contains the primary key being referenced.
Column
Select the table column that references the primary key column in the referenced table.
Referenced Column
Select the name of the primary key column in the referenced table.
Cascade delete
Check this box if this is a foreign key with cascade delete. A foreign key with a cascade delete specifies that if a row in the parent table is deleted, then the corresponding rows in the child tables are automatically deleted. When this box is unchecked, the deletion of a row in a parent table will be aborted if a corresponding row exists in child tables. See Cascade delete.

Figure: Foreign Key relationship in diagram


This figure is a screenshot of a database diagram, with a foreign key relationship shown by an arrow between two tables. The arrow is labeled.

The foreign key constraint is added to the table in the Structure view. Select the foreign key constraint to display or edit its properties.

Figure: Foreign Key in Database Structure view


This figure is a screenshot of the Database Structure view, with the Foreign Key node as a child of the table and the properties shown in the Properties view.

Add a foreign key by drawing relationship

You can also define the foreign key by drawing the relationship between columns using the mouse. Right-click on the background of the meta-schema diagram and select Add Foreign Key. Select the foreign key column in one table, and drag the mouse towards the primary key column in the table to be referenced. Once you release the mouse button, the relationship is displayed and the foreign key is added. Confirm the foreign key properties in the Properties view.