Create Foreign Key

To create a Foreign Key, follow the steps below:

  1. Locate the required Tables in a diagram.
  2. Select an Associate connector in the Class Relationships page of the Enterprise Architect UML Toolbox.
  3. Click on the Table to contain the Foreign Key (source) and draw the connector to the other Table (target).
  4. Right-click on the connector to display the context menu, and select the Foreign Keys option. The Foreign Key Constraint dialog displays.
     
    ForeignKeyConstraint

 

  1. If necessary, edit the default name for the Foreign Key.
  2. Highlight the columns involved in the Foreign Key relationship.
  3. 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:

PrimaryKeyDiagram

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 uphand and downhand buttons.

Tip:

If you are defining a MySQL database and want to use Foreign Keys, you must set the table type to enable this.

CompositeForeignKey

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

ForeignKey