Pour les tables MyIsam, MySQL ne gère l'intégrité référencielle qu'au niveau "déclaration", il n'y a aucun tests réels. Voici un extrait de la doc de MySQL 5.0: A foreign key constraint is not required merely to join two tables. For storage engines other than InnoDB, it is possible when defining a column to use a REFERENCES tbl_name(col_name) clause, which has no actual effect, and serves only as a memo or comment to you that the column which you are currently defining is intended to refer to a column in another table. MySQL does not perform any sort of CHECK to make sure that col_name actually exists in tbl_name (or even that tbl_name itself exists).
MySQL does not perform any sort of action on tbl_name such as deleting rows in response to actions taken on rows in the table which you are defining; in other words, this syntax induces no ON DELETE or ON UPDATE behavior whatsoever. (Although you can write an ON DELETE or ON UPDATE clause as part of the REFERENCES clause, it is also ignored.)
This syntax creates a column; it does not create any sort of index or key.
This syntax will cause an error if used in trying to define an InnoDB table.
...
Il faut donc utiliser des tables InnoDB:
In MySQL Server 3.23.44 and up, the InnoDB storage engine supports checking of foreign key constraints, including CASCADE, ON DELETE, and ON UPDATE. See Section 14.2.6.4, “FOREIGN KEY Constraints”.
For storage engines other than InnoDB, MySQL Server parses the FOREIGN KEY syntax in CREATE TABLE statements, but does not use or store it. In the future, the implementation will be extended to store this information in the table specification file so that it may be retrieved by mysqldump and ODBC. At a later stage, foreign key constraints will be implemented for MyISAM tables as well.
Si tu veux une vraie intégrité référencielle, soit tu utilises des tables InnoDB, soit tu regardes plutôt du côté de HF C/S ou MaxDB.
Frédéric. |