Home > Article > Backend Development > marc by marc jacobs official website mysql creates foreign keys
Prerequisite for establishing a foreign key: The columns of this table must be of the same type as the foreign key (the foreign key must be the primary key of the table).
Function of foreign keys: To associate two tables, foreign keys can only refer to the values of columns in the table!
Specify the primary key keyword: foreign key (column name)
Quote the foreign key keyword: references
Event triggering restrictions: on delete and on update, the parameter cascade( can be set Follow foreign key changes), restrict (restrict foreign key changes in the table), set Null (set null value), set Default (set default value), [default] no action
For example:
outTable table primary key id type int
Create Table with foreign keys:
create table temp(
id int,
name char(20),
foreign key(id) references outTable(id) on delete cascade on update cascade);
Instructions: Set the id column as external The key refers to the id column of the outer table outTable. When the value of the foreign key is deleted, the corresponding column in this table is filtered. When the value of the foreign key changes, the corresponding column value in this table changes.
The above introduces the creation of foreign keys in mysql by marc by marc jacobs official website, including the content of marc by marc jacobs official website. I hope it will be helpful to friends who are interested in PHP tutorials.