I just figured out how to set foreign keys on navicat for mysql this morning. Now I share it. I hope it will be helpful to everyone.
Recommended tutorial: MySQL introductory video
Let me first introduce the basic situation. Now there are two tables, one is the teacher table and the other is the dept table. Now I want to set the dept attribute in the teacher table as a foreign key and associate the code attribute in the dept table. The specific situation is as shown in the figure; OK, the basic situation is introduced, now let’s teach you how to set foreign keys in navicat for mysql.
1. Open my navicat, then find my teacher table, select it, and then click ‘design table’ on the menu bar.
#2. Find "Foreign Keys" in the pop-up dialog box, and then stand alone.
#3. Then an interface for setting foreign keys will appear, with a total of seven columns. Let’s briefly introduce the meaning of these columns.
‘name’: You don’t need to fill it in. The system will automatically generate it after you save it successfully.
‘FieldName’: Which key you want to set as a foreign key. Select ‘dept’
here. ‘Reference DadaBase’: the database associated with the foreign key.
'Reference Table': The associated table, here is the dept table
'Forgin filed Names': The associated field, here is the code
'ondelete': It is deleted action when selecting. My choice here is setNull, which means that when the associated table is deleted, the teacher>dept field will be set to null.
‘onupdate’: It is the action selected when updating. My choice here is CASCADE, which means that when the associated table is updated, the teacher>dept field will be set to cascade update.
#4. After the settings are completed, click ‘save’ to save and exit. You can also click ‘add Foreign Key’ to add another foreign key.
The above is the detailed content of How to set foreign keys in navicat. For more information, please follow other related articles on the PHP Chinese website!