0

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?

PeakGen
  • 21,894
  • 86
  • 261
  • 463
  • You can use TRIGGERS – cppcoder Sep 17 '14 at 05:38
  • Another one with demo [*`Mysql create table with multiple foreign key on delete set null`*](http://stackoverflow.com/questions/15880070/mysql-create-table-with-multiple-foreign-key-on-delete-set-null) – M Khalid Junaid Sep 17 '14 at 05:39
  • @MKhalidJunaid: I do not agree with your decision on making this as `duplicate`. I need some example code with explanation to understand. – PeakGen Sep 17 '14 at 05:41
  • @Sniper i have also provided another link above your comment which has a demo too and the first one has explanation what else you need ? – M Khalid Junaid Sep 17 '14 at 05:44

0 Answers0