Trigger before delete MySql

后端 未结 3 1619
说谎
说谎 2020-12-11 20:51

I have a table named user. This table has a foreign key to a department table. One user can be associated with one department. Before deleting a department, I would like to

3条回答
  •  攒了一身酷
    2020-12-11 21:40

    I haven't tested it, but based on the documentation, this looks about right:

    CREATE TRIGGER update_user_before_delete BEFORE DELETE ON department
      FOR EACH ROW BEGIN
        UPDATE user SET department = 1 WHERE department = OLD.department;
      END;
    

提交回复
热议问题