The following articles mainly refer to the definition of MYSQL Foreign keys and the prerequisites for establishing MYSQL Foreign keys, that is, the related columns of the table must belong to the same type as the foreign key (the foreign key must be the external primary key. We all know that foreign keys are used to associate two tables. Foreign keys can only reference the values of columns in the External table!
Specify the primary key Keyword: foreign key (column name)
Reference MYSQL key keywords: references <foreign key table name> (foreign key column name)
Event trigger restrictions: on delete and on update. You can set the parameters cascade, restrict, and set Null ), set Default sets the Default value), [Default] no action
For example:
OutTable table primary key id type int
Create a table with foreign keys:
- Create table temp (
- Id int,
- Name char (20 ),
- Foreign key (id) references outTable (id) on delete cascade on update cascade );
The above content is an introduction to the MYSQL foreign key. I hope you will get some benefits.