He doesn’t know if it’s good design practice, but he probably has a composite foreign key for one table that is part of a composite primary key for another table.
Say we have a table test1 that has a composite primary key (A, B)
Now we can have a table in which test2 has the primary key (P, Q, R), where in (P, Q) the links are test2 (A, B) of test2.
I ran the following script in the MySql database and it works fine.
CREATE TABLE `test1` ( `A` INT NOT NULL, `B` VARCHAR(2) NOT NULL, `C` DATETIME NULL, `D` VARCHAR(45) NULL, PRIMARY KEY (`A`, `B`));
CREATE TABLE `test2` ( `P` INT NOT NULL, `Q` VARCHAR(2) NOT NULL, `R` INT NOT NULL, `S` DATETIME NULL, `T` VARCHAR(8) NULL, PRIMARY KEY (`P`, `Q`, `R`), INDEX `PQ_idx` (`P`,`Q` ASC), CONSTRAINT `PQ` FOREIGN KEY (`P`, `Q`) REFERENCES `test1` (`A`,`B`) ON DELETE CASCADE ON UPDATE CASCADE);
In the above case, the database expects the combination (A, B) to be unique, and it is the primary key in table test1.
But if you try to do something like the following, the script will fail. The database will not allow the creation of the test2 table.
CREATE TABLE `test2` ( `P` INT NOT NULL, `Q` VARCHAR(2) NULL, `R` DATETIME NULL, `S` VARCHAR(8) NULL, `T` VARCHAR(45) NULL, INDEX `P_idx` (`P` ASC), INDEX `Q_idx` (`Q` ASC), CONSTRAINT `P` FOREIGN KEY (`P`) REFERENCES `test1` (`A`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `Q` FOREIGN KEY (`Q`) REFERENCES `test1` (`B`) ON DELETE CASCADE ON UPDATE CASCADE);
In the above case, the database expects column A to be unique individually, and the same goes for column B. It does not matter if the combination (A, B) is unique.