I want a trigger to DELETE from 2 tables in MySQL

后端 未结 5 1678
渐次进展
渐次进展 2020-12-10 13:16

I have 3 MySQL tables (food, apple, and orange).

I want to delete rows from:

apple(idapple, iduser, name) 
ora         


        
5条回答
  •  鱼传尺愫
    2020-12-10 13:46

    I forgot the BEGIN and END blocks in the trigger. And you have to delete from tables sequentially like this:

    CREATE TRIGGER `food_before_delete`     
      AFTER DELETE ON `food`     
      FOR EACH ROW     
    BEGIN
      DELETE FROM apple
      WHERE apple.iduser=NEW.iduser;
    
      DELETE FROM orange
      WHERE orange.iduser=NEW.iduser; 
    END
    

提交回复
热议问题