I am programming a trigger (in workbench 8) for mysql that is triggered after an insert to the table, my trigger is as follows:
DELIMITER //
Drop trigger if exists tr_pago;
CREATE TRIGGER tr_pago after insert on pago for each row
BEGIN
declare ultimoidpago int;
declare idcompromisopago int;
declare idunidadrecaudadora int;
declare idboleta int;
Set ultimoidpago = new.IdPago
Set idcompromisopago = (select new.CP_IdCompromisoPago from pago where IdPago = ultimoidpago);
Set idunidadrecaudadora = (select UR_IdUnidadRecaudadora from compromiso_pago where IdCompromisoPago = idcompromisopago);
Set idboleta = (select IdBoleta from boleta where UR_IdUnidadRecaudadora = idunidadrecaudadora );
update pago set new.B_IdBoleta = idboleta where IdPago = ultimoidpago;
END
DELIMITER //
But when making an insert to the payment table, I get the following error:
Error Code: 1442. Can't update table 'pago' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.