Bonjour,
je me lance dans MySQL, et je souhaiterai savoir s'il est possible à partir d'une table, d'avoir 2 clés étrangères qui pointent vers une même table.
Les 2 tables :
- Table parent : Customer
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 CREATE TABLE `customer` ( `No.` varchar(20) NOT NULL, `Name` text, PRIMARY KEY (`No.`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
- Table Enfant : Ecritures
J'ai bien entendu fait le test qui me retourne un message d'erreur.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 CREATE TABLE `ecriture_client` ( `Entry No.` int(11) NOT NULL, `customer_no.` varchar(20) DEFAULT NULL, `posting_date` date DEFAULT NULL, `Sell-to Customer No.` varchar(20) DEFAULT NULL, PRIMARY KEY (`Entry No.`), KEY `customer_no.` (`customer_no.`), KEY `Sell-to Customer No.` (`Sell-to Customer No.`), CONSTRAINT `ecriture_client_fk2` FOREIGN KEY (`Sell-to Customer No.`) REFERENCES `customer` (`No.`) ON DELETE CASCADE, CONSTRAINT `ecriture_client_fk1` FOREIGN KEY (`customer_no.`) REFERENCES `customer` (`No.`) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Partager