Bonjour,
j'ai 2 tables :
Code sql : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10 DROP TABLE IF EXISTS `projet`; CREATE TABLE `projet` ( `idprojet` SMALLINT NOT NULL, `description` varchar(50) DEFAULT NULL, `datelancement` date DEFAULT NULL, `pays` varchar(50) DEFAULT NULL, `ville` varchar(50) DEFAULT NULL, `budget` float DEFAULT NULL, `sommecollectee` float DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Code sql : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9 DROP TABLE IF EXISTS `commentaire`; CREATE TABLE `commentaire` ( `idcomment` SMALLINT NOT NULL, `datecomment` date DEFAULT NULL, `contenu` text DEFAULT NULL, `note` SMALLINT DEFAULT NULL, `idprojet` SMALLINT NOT NULL, `idmembre` SMALLINT NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
avec une clé étrangère de la table commentaire sur la table projetet si je tente de supprimer un enregistrement dans projet étant donné un certain commentaire :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 ALTER TABLE `commentaire` ADD CONSTRAINT `commentaire_ibfk_1` FOREIGN KEY (`idprojet`) REFERENCES `projet` (`idprojet`);
DELETE P FROM projet P join commentaire C ON P.idprojet=C.idprojet where C.idcomment=18ça veut pas à cause de la clé étrangère :Comment puis-je faire ?Cannot delete or update a parent row: a foreign key constraint fails (`secours`.`commentaire`, CONSTRAINT `commentaire_ibfk_1` FOREIGN KEY (`idprojet`) REFERENCES `projet` (`idprojet`))
Partager