Create a Foreign Key

Create a Foreign Key

Step

Action

See also

1

Locate the required Tables in a diagram.

Both tables must have defined database types.

 

Set The Database Type

2

Select an Associate connector in the Class Relationships page of the Toolbox.

 

 

3

Click on the Table to contain the Foreign Key (source) and draw the connector to the target Table.

 

 

4

Right-click on the connector and select the Foreign Keys context menu option.

The Foreign Key Constraint dialog displays.

 

 

5

The default foreign key name is set by the Foreign Key Name Template.

To change the name to something other than the default provided by the template, select the Override Template checkbox and edit the foreign key name.

Optionally, you can create a Foreign Key Index automatically using the Create Index on Foreign Key field. You can control the name of the automatically generated Foreign Key Index by setting the template.

 

Define Foreign Key Name Template

 

Define Foreign Key Index template

6

In the Source: panel and the Target: panel, click on the name of each of the two columns involved in the Foreign Key relationship.

 

 

7

From the On Delete and/or On Update combo boxes, select the appropriate referential integrity constraint.

 

 

8

Click on the Apply or OK buttons to automatically generate the Foreign Key operations.

 

 

Example

This example shows what a Foreign Key looks like in a diagram:

PrimaryKeyDiagram

Notes

For MySQL databases, Foreign Keys are supported for InnoDB tables only
 
InnoDB is the default MySQL storage engine as of version 5.5; if you are modeling a MySQL database that is earlier than version 5.5 and you want to use Foreign Keys, you must set the Engine Tagged Value to InnoDB

Learn more