Navicat Adding a foreign key detail procedure in MySQL
/**
* @author Blovedr
* function: navicat add foreign key in MySQL
* Date: June 21, 2018 22:42
* Note: Learn the database MySQL point of record, thank you online the great God to share experience, welcome the great God of criticism and guidance and communication.
*/
1. Open the Navicat connection on the database and create a new database: "test";
2. Create two table "emp" (primary table) and "dept" (from table) in database "test"
"emp" (Main Table---employee table)
"dept" (from Table---Department table)
3. Set the "emp" (Main Table) and "dept" (from the table) options
Table type:InnoDB,
Character Set: Utf8–utf-8 Unicode (default),
Collation: Utf8_general_ci (default),
Auto Increment : Set yourself (the primary table EMP must be the same as from table dept)
4 . Set foreign keys
FOREIGN Key Name (name): Can not fill, the system automatically generated;
Field name (Field Name): Just set 'dept_id' as the foreign key ;
Reference Database (Reference dadabase): The database associated with the foreign key (' dept_id ');
reference table (Reference table): The associated table , here is the dept table ;
Outer column name (Outside field name): The associated field (here is "dept_id", which can be the same as the column name);
Delete : Delete time selected action (here Select CASCADE);
Refresh : The action selected when updating (choose CASCADEhere)CASCADE--- That is, when the associated table is updated, the dept_id in the EMP is updated as well .
Note : The Add foreign key database engine must be InnoDB;
The associated field data type must be the same;
The associated field data from the table must be in the primary table.
5. Use navicat to add foreign keys to MySQL .
Navicat Adding a foreign key detail procedure in MySQL