Foreign keys

Last modified: October 1, 2024

A foreign key constraint (also called a referential integrity constraint) designates a column as the foreign key and establishes a relationship between that foreign key and a specified primary or unique key, called the referenced key. The foreign key and the referenced key can be in the same table or view.

You can define multiple foreign keys in a table or view. Also, a single column can be part of more than one foreign key.

The following restrictions are actual for foreign constraints:

To create a foreign key:

Open the table you need and choose New Foreign Key from the Table menu. Add required columns, select referenced table and referenced constraint and click OK. You can also switch to the Constraints tab and create the constraint within the shortcut menu.

Note

To create a foreign key, the referenced table should have a unique index, otherwise dbForge Studio will prompt you to create it. Click Yes in the appeared dialog and the unique index will be added.

To edit a foreign key:

Navigate to the constraint in Database Explorer and double-click it or open the table that owns the constraint, switch to the Constraints tab and click Edit Constraint from the shortcut menu.

To drop a foreign key:

Navigate to the constraint in Database Explorer and select Delete from the shortcut menu. Alternatively, open the table that owns the key, switch to Constraints tab and choose Delete Constraint from its shortcut menu.