I have 2 tables, Product
and Category
. The relationship is Product has a Category
. That means, the Primary Key of the Category
table is the foreign key of the Product
table. Product table has 2 columns, Name
and idCategory
.
I am using MySQL InnoDB
as the database.
Now my question is this; imagine I delete the category "Fruits" in Category
table. In my Product
table, "Apple", "Orange" and "Grapes" are "Fruits". When I delete the Fruits from Category
, the idCategory
of the "Apple", "Orange" and "Grapes" in Product
table should be set to NULL
Is there any automatic process in MySQL to do this?