Quick Start
Connect to MySQL
Databases
Tables
Adding Fields and Choosing Data Types
Customising Fields
Primary Keys and Indexes
Filter Wizard
Foreign Keys
Import/Export
Queries
Visual Query Builder
Stored Procedure
Data
Manage Users
Backup
Data Transfer
Schedule
Server Monitor
Maintaining your databases/tables
  Working With Foreign Keys
 

Starting from version MySQL version 3.23.43b, foreign keys are supported for innodb tables.

Create or Edit a Foreign key

  1. Open the table in Design View
  2. Select the Foreign keys tab
  3. To add a new foreign key, click Add Foreign Key button from the toolbar
  4. Select the fields to be included in the foreign key from a popup panel, by double-clicking on the Field Names grid or clicking the button on the right side of the field
  5. To add fields, choose the fields one by one from Available Fields
  6. You can see the selected fields on the Included Fields.
  7. Then select the reference table from the list.
  8. Select the foreign fields from the popup panel.
  9. Choose the on delete action and on update action from the list.
On Delete Action
CASCADE Deletes the corresponding foreign key.
SET NULL Sets all the columns of the corresponding foreign key to NULL.
NO ACTION Does not change the foreign key.


On Update Action
CASCADE Updates the corresponding foreign key to the new value of the primary key.
SET NULL Sets all the columns of the corresponding foreign key to NULL.
NO ACTION Does not change the foreign key.
RESTRICT Produces an error indicating that the update would create a foreign key constraint violation.

Click Save or Save As from the toolbar when you are ready to save the table

Delete a Foreign key

  1. Open the table in Design View
  2. Select the Foreign Keys tab
  3. Select the foreign key you want to delete and click Delete Foeign Key button from the toolbar
  4. Click Save or Save As from the toolbar when you are ready to save the table

NOTE:

  1. Both tables have to be InnoDB type
  2. Deleting or editing foreign keys are only supported since MySQL version 4.0.13
  3. Indexes are required for the fields involved. If you have not created the required indexes, Navicat can help you to create them when you save the tables