Update Trigger in Mysql

1

I do not know much about Mysql and I need to do a trigger to update a line right after insertion. When the user registers an order he selects how many orders he wants. In the database a type is saved in one column and in another column the amount that it requested. I wish that every time I enter a new request my trigger updates the type field for (quantity-type) My trigger is like this but nothing happens after inserting a new record:

delimiter $$
create trigger Atualiza_Pedido

after insert on loja.pedido for each row

Begin

if new.method = 'metodo' 

then

update loja.pedido
set tipo = concat(new.quantidade,'-', new.tipo)
where id = new.id;

end if;
END$$
    
asked by anonymous 29.06.2017 / 20:24

1 answer

0

You do not have to UPDATE , just set the value:

delimiter $$
create trigger Atualiza_Pedido

before insert on loja.pedido for each row
Begin
    if new.method = 'metodo' then
        set new.tipo = concat(new.quantidade,'-', new.tipo);
    end if;
END$$

Actually, this TRIGGER has to be executed before inserting and not after, so I changed AFTER to BEFORE .

    
29.06.2017 / 20:31