I have two MySQL tables: collections
and privacy_level
.
I define them with a foreign key relationship as such:
Also you can use ON DELETE CASCADE
, that means when you delete the parent all the children will be removed automatically, this is useful when you have a table associated with another that contains some parameters or settings.
ON DELETE RESTRICT
means you can't delete a given parent row if a child row exists that references the value for that parent row. If the parent row has no referencing child rows, then you can delete that parent row.
ON DELETE RESTRICT
is pretty much superfluous syntax, because this is the default behavior for a foreign key anyway.