Create Foreign Key
To create a Foreign Key, follow the steps below:
- Locate the required Tables in a diagram. Both tables must have defined database types.
- Select an Associate connector in the Class Relationships page of the Enterprise Architect UML Toolbox.
- Click on the Table to contain the Foreign Key (source) and draw the connector to the other Table (target).
- Right-click on the connector to display the context menu, and select the Foreign Keys option. The Foreign Key Constraint dialog displays.

- 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.
- Highlight the columns involved in the Foreign Key relationship.
- Click on the Save button to automatically generate the Foreign Key operations.
You have created the Foreign Key. The example below shows how this looks in a diagram:

Composite Foreign Key
To create a composite Foreign Key, select the appropriate columns and click on the Save button. The Foreign Key columns are sorted according to datatype to match the datatypes of the targeted composite Primary Key. If required, you can change the order of the key columns by clicking on the
and
buttons.
Tip: |
If you are defining a MySQL database and want to use Foreign Keys, you must set the table type to enable this. |

This creates the composite Foreign Key. The example below shows how this looks in a diagram:

The material ("material" includes all pages, documents and on-line graphics) on this web site is protected by copyright law. (C) 1998-2010 Sparx Systems Pty Ltd.