Starting from version MySQL version 3.23.43b, foreign keys
are supported for innodb tables.
Create or Edit a Foreign key
- Open the table in Design View
- Select the Foreign keys tab
- To add a new foreign key, click Add Foreign Key button
from the toolbar
- 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
- To add fields, choose the fields one by one from Available
Fields
- You can see the selected fields on the Included Fields.
- Then select the reference table from the list.
- Select the foreign fields from the popup panel.
- 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
- Open the table in Design View
- Select the Foreign Keys tab
- Select the foreign key you want to delete and click Delete
Foeign Key button from the toolbar
- Click
Save or
Save As from the toolbar when you are ready to save the
table
NOTE:
- Both tables have to be InnoDB type
- Deleting or editing foreign keys are only supported since
MySQL version 4.0.13
- 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
|