1. Several modes
. Cascade mode
When updating/delete records on the parent table, synchronize update/delete the matching records of the child table
. Set null mode
Update/delete records on the parent table When setting the column of matching records on the child table to null, please note that the foreign key column of the child table cannot be not null
. No action method
If there are matching records in the child table, the correspondence to the parent table is not allowed Candidate keys perform update/delete operations
. Restrict mode
is the same as no action, both of which check foreign key constraints immediately
. Set default mode
When the parent table changes, the child table sets the foreign key column to A default value but Innodb cannot recognize it
2. About the main table, foreign key, and slave table
A person’s identity is unique, but he can do many things. The identity is the master table, and the facts are from the slave table, and from the table The marked id is the user's identity, which is the foreign key of the main table.
For example, customer table and product table
A customer may purchase multiple products. The associated identity is the customer's number or name.
The foreign key is set in the product table.
Summary: The primary key table is the table that is referenced, and the foreign key table is the table that references other tables.