0
I’m having trouble creating a Trigger that modifies more than one table.
DROP TRIGGER IF EXISTS vendedor_pago;
DELIMITER $$
CREATE TRIGGER vendedor_pago AFTER UPDATE ON parcelas
FOR EACH ROW
BEGIN
UPDATE vendas, comissao, parcelas
SET vendas.`conf_pagamento` = 1,
comissao.`pago` = IF(parcelas.`parcelas_pagas` = parcelas.`num_parcelas`, 1, 0)
WHERE parcelas.`id_venda` = comissao.`id_venda`
AND comissao.`id_venda` = vendas.OLD.`id`
AND vendas.`id` = parcelas.`id_venda`
END$$
DELIMITER ;
I don’t even know if the shape vendas.OLD.id
is correct. The following error is returned when executing:
1064 - You have a syntax error in your SQL next to 'END' on the line 10
I would also like to know if the FOR EACH loop is really necessary, since I want to change only one record of each table.
You forgot the
BEGIN
andEND
– Sorack
Still an error. I updated the question with the result.
– Jhonatan Pereira
Lack also
FOR EACH ROW
after the table name. Take a look at the documented examples– Sorack
Is this really necessary when I want to update only 1 record in the table? Updating the question again.. Take a look
– Jhonatan Pereira