Cristoforo Cervino
Cristoforo Cervino

Reputation: 71

DELETE CASCADE on a child row delete parent?

I have 3 tables. The last two tables have a foreign key to the first on the same field. Both foreign keys are set to UPDATE CASCADE, DELETE CASCADE. When I delete a child-row in the second table, the parent row in the first table remains unchanged. But when I delete a child-row in the third table, the first row in the table is deleted!

Foreign keys should not behave in the same way as both daughters?

Upvotes: 4

Views: 1767

Answers (1)

dwurf
dwurf

Reputation: 12749

My guess is that table 2 uses MyISAM tables (which do not support foreign keys) while the other two tables are using the InnoDB engine (which do support foreign keys).

From the documentation:

Foreign key relationships involve a parent table that holds the central data values, and a child table with identical values pointing back to its parent. The FOREIGN KEY clause is specified in the child table. The parent and child tables must both be InnoDB tables. They must not be TEMPORARY tables.

Upvotes: 1

Related Questions