I have a table with payments where, in addition to the amount of the payment, the person’s balance is kept at the time of payment. I wanted to do the following with the help of a mysql trigger: when deleting a payment, the balance at the beginning of the subsequent transactions decreased by the amount of the payment being deleted.
CREATE TRIGGER `before_delete_payment` BEFORE DELETE ON `payment` FOR EACH ROW BEGIN UPDATE `payment` SET `value_before` = `value_before` - OLD.`amount` WHERE `time` > OLD.`time`; END But, accordingly, an error occurs that the trigger cannot work with the table with which it is associated.
How can I do in this case? To implement all not in a DB, separate request?