In my database I have a table Employee
that has recursive association (an employee can be boss of other employee):
create table if not exists `e
Instead of doing a hard delete, do a soft delete. Add is_deleted column and set it to 1 if you want to delete the row. Create after_update trigger on the table.
DELIMITER $$
CREATE
TRIGGER `Employee_after_update` AFTER UPDATE
ON `Employee`
FOR EACH ROW BEGIN
UPDATE Employee
...............
WHERE NEW.is_deleted=1;
DELETE FROM Employee WHERE NEW.is_deleted=1
END$$
I am not sure that you can update the same table for after_{insert,delete,update}. Please check this
Use a stored procedure:
UPDATE b
SET b.mssn = a.mssn
FROM EMPLOYEE a
JOIN EMPLOYEE b ON b.mssn = a.ssn
WHERE a.ssn = @deletedBoss
DELETE FROM employee WHERE ssn = @deletedBoss
With a stored procedure, you can simply delete the rows you want, and after that, update the same table. That should prevent the error message.