I have a question of interest:
I have 2 tables in mysql with InnoDb
.
table tbl_a
has a primary key, named a_id
;
table
The foreign key constraint even without ON DELETE / UPDATE CASCADE
ensures that if you insert a value into the child table, that it has a correctly matching value in the parent table (or is NULL
if the FK column is nullable). Attempting to insert an invalid value into the child table's FK column would result in error when the constraint fails, so your data integrity is protected.
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails
Defining the foreign key constraint also implicitly defines an index on the FK column in the child table, which although you could have manually defined the index, will improve joining performance.
ON DELETE NO ACTION
(which is the same as omitting the ON DELETE
clause) will actively prevent deletion of a parent row if it is referenced by any child table, not passively allow it to be deleted without affecting child rows.