October 2022
Intermediate to advanced
380 pages
9h 35m
English
In standard SQL, the columns referenced by a foreign key must be the PRIMARY KEY or a UNIQUE KEY of the Parent table. InnoDB supports a non-standard feature: a foreign key does not have to include the whole set of columns in the referenced key. The foreign key is also allowed to reference a non-unique index in the parent table, instead of a PRIMARY KEY or UNIQUE KEY. The only rule is that the columns referenced by the foreign key must be the left-most columns of a key or index. Otherwise you get an error that tells you no index was found in the Parent table with those columns as the left-most columns.
| | CREATE TABLE Parent ( |
| | parent_id1 INT, |
| | parent_id2 ... |
Read now
Unlock full access