MySQL permits setting a foreign key constraint that references only one column of a composite primary key

database-designforeign keyMySQL

In the database structure depicted in the diagram that follows

the columns key1 & key2 make up the composite primary key of table4, but in table3 I'm able to set up a foreign key constraint that makes a reference to key1 only.

Why does MySQL allow this? Does the above database structure make no sense at all?

Best Answer

Quote from the documentation:

InnoDB allows a foreign key constraint to reference a non-unique key. This is an InnoDB extension to standard SQL.

Although this may come as a surprise, it is "documented behaviour". This is probably one of these cases where you/we must just accept that things have been implemented in a certain manner ie InnoDB have implemented foreign keys this way.

Whether the design (in question) makes sense or not depends on the underlying business rules. There may well be situations that require such a constraint.