Error executing a trigger

0

I have a problem with a trigger that when I make an insert of a record I want to automatically pass a value that comes by default is 1 to 0 only that is always giving this error.

Can not update table 'receipts' in stored function / trigger because it is already used by statement which invoked this stored function / trigger.

Trigger

CREATE TRIGGER actrecibo AFTER INSERT on Recibos
FOR EACH ROW 
BEGIN
        UPDATE recibos set is_new = 0 WHERE id = NEW.id;
END

Does anyone know how to look for this and how can I resolve it?

    
asked by anonymous 23.05.2016 / 18:57

2 answers

0

I think with BEFORE you can do that.

CREATE TRIGGER actrecibo BEFORE INSERT on Recibos
FOR EACH ROW 
BEGIN
      SET NEW.id = ( SELECT MAX(id) FROM Recibos ) + 1
END
    
23.05.2016 / 18:59
0

I did not understand the context of using Trigger, but analyzing only the code I noticed the following.

After INSERT you are updating the is_new = 0 field of the record you just entered.

If so, you can try this:

CREATE TRIGGER actrecibo BEFORE INSERT on Recibos
FOR EACH ROW 
BEGIN
      SET NEW.is_new = 0;
END
    
21.09.2016 / 16:38