Can a foreign key reference a non-unique index?

From MySQL documentation:

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

However, there is a pratical reason to avoid foreign keys on non-unique columns of referenced table. That is, what should be the semantic of “ON DELETE CASCADE” in that case?

The documentation further advises:

The handling of foreign key references to nonunique keys or keys that contain NULL values is not well defined (…) You are advised to use foreign keys that reference only UNIQUE (including PRIMARY) and NOT NULL keys.

Leave a Comment