Foreign Keys

A foreign key constraint (also called a referential integrity constraint) designates a column as a 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 a 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 select New Foreign Key on the Table menu. Add required columns, select a referenced table and referenced constraint and click OK. You can also switch to the Constraints tab and create the constraint within the pop-up 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 select Edit Constraint on the shortcut menu.

To Drop a Key

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