Bonjour,
Je me mets un peu a mysql et je n'arrive pas a tester l'existence du foreign key.
Le code me semble bon mais j'ai un message d'erreur (MySQL Database Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IF NOT EXISTS (select 1 from INFORMATION_SCHEMA.TABLE_CONSTRAINTS where constrai' at line 1 12 0
):)
Voilà je ne suis pas contre un petit coup de pouce...
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8 DELIMITER $$ IF NOT EXISTS (select 1 from INFORMATION_SCHEMA.TABLE_CONSTRAINTS where constraint_name = 'FK_NEWS_USER') THEN ALTER TABLE NEWS ADD CONSTRAINT `FK_NEWS_USER` FOREIGN KEY (`iduser`) REFERENCES `USER` (`iduser`); END IF; $$ DELIMITER ;
Merci
Partager