I have an error creating this trigger in a MySql db:
CREATE TRIGGER AggiornaQuantitaLotto AFTER UPDATE ON Lotti
FOR EACH ROW
BEGIN
DECLARE Differenza INT DEFAULT 0;
IF OLD.Quantita <> NEW.Quantita THEN
SET Differenza = NEW.Quantita - OLD.Quantita;
UPDATE Giacenze
SET Totale = Totale + Differenza,
Disponibile = Disponibile + Differenza
WHERE CodP = NEW.CodP;
END IF;
END;
Where am I going wrong? the error message says:
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 4
Where is the line 4 is the 'DECLARE ...'
Thanks in advance