Details
-
Bug
-
Status: Stalled (View Workflow)
-
Minor
-
Resolution: Unresolved
-
10.3(EOL), 10.4(EOL)
-
None
-
Linux CentOS 7.2
Description
A foreign key should only be able to reference a UNIQUE or PRIMARY KEY constraint, but MariaDB allows any key/index to be referenced. To reproduce:
CREATE TABLE t1(c1 INT NOT NULL PRIMARY KEY, |
c2 INT NOT NULL, |
KEY(c2)); |
 |
CREATE TABLE t2(c1 INT NOT NULL PRIMARY KEY, |
c2 INT NOT NULL, |
FOREIGN KEY (c2) REFERENCES t1(c2)); |
This is invalid in the SQL Standard as well as according to MariaDB Knowledge base: https://mariadb.com/kb/en/library/foreign-keys/ which states "The referenced columns must be a PRIMARY KEY or a UNIQUE index".