插入后MySQL触发器更新

时间:2019-05-31 14:27:00

标签: mysql sql database-trigger

在插入SQL触发器后进行更新的正确语法是什么?

我正在尝试:

    CREATE TRIGGER movimentacoes AFTER INSERT ON
    mov FOR EACH ROW
BEGIN
    UPDATE
        cooperados
    INNER JOIN mov ON mov.id_coop = cooperados.id
    SET
        cooperados.integralizadas = cooperados.integralizadas + mov.valor
    WHERE
        mov.id_coop = cooperados.id

我正在使用laravel构建应用程序,此触发器必不可少。

1 个答案:

答案 0 :(得分:0)

大概您打算这样做:

DELIMITER $$

CREATE TRIGGER movimentacoes AFTER INSERT ON mov
FOR EACH ROW
BEGIN
    UPDATE cooperados c
        SET integralizadas = c.integralizadas + new.valor
    WHERE c.id = new.id_coop;
END;

DELIMITER ;