Trigger MySQL - Error syntax

0

Can anyone tell me where I'm wrong in the Trigger below?

CREATE TRIGGER atualiza_produto 
AFTER INSERT 
ON item_venda FOR EACH ROW
BEGIN
UPDATE produto SET vendido = 's' WHERE id = NEW.id_produto;
END

The error message:

Você tem um erro de sintaxe no seu SQL próximo a '' na linha 5
    
asked by anonymous 14.04.2018 / 03:10

1 answer

0

The MySql has ; as the end of each query , in which case it is trying to execute two querys instead of one, precisely because ; is separating.

In order to avoid this, it is necessary to show MySql what ; is not ending query and yes it is part of the context, for that there is DELIMITER , in your case it would look like this :

DELIMITER $$
    CREATE TRIGGER atualiza_produto AFTER INSERT ON item_venda FOR EACH ROW
    BEGIN
        UPDATE produto SET vendido = 's' WHERE id = NEW.id_produto;
    END
$$

Everything between DELIMITER $$ and $$ should be performed together and not separating querys to ; .

See more here .

    
14.04.2018 / 04:21