Mysql – How do automaticly delete rows from other tables

deleteforeign keyMySQL

I have a MySql DB.

I have a table – recipes.
Also have 2 tables -ingredients and instructions. both have for each entry – a foreign key to the related recipe.

I want that when I delete an entry from the recipes table – to automaticly delete the related ingredients entries and instruction entries.

How?

Best Answer

Whatever you are trying to do can easily be done by

USING ON DELETE CASCADE AND ON UPDATE CASCADE(IF Required)

While creating the foreign keys on your table.

For your reference have a look at FOREIGN KEY Constraints.