To create a relationship in MySQL Workbench:
- Create a database model (either create a new model or reverse engineer an existing database)
- Viewing the database model, double click on the first table of the relationship
- The bottom pane will open with the table details. Click on the Foreign Keys tab
- In the left pane, select the foreign key field and referenced table
- In the middle pane, select the foreign column and referenced (primary key) column
- In the right pane, set any Update/Delete actions you’d like to occur when a primary key record is updated or deleted
The relationship is now established. Repeat steps 4 to 6 for any other foreign key columns in that table.
To create a database from this model:
Example
Here is an example of establishing a relationship using a database model:
This example is showing two relationships have been established on the “Albums” table. Clicking on a foreign key in the left pane refreshes the middle and right panes with its details.