0
I’m having difficulties with the if() syntax in phpmyadmin. I have to create a TRIGGER to insert information in a log when the name of an animal table animals is changed. But there is a syntax error in if(). When I take out if it works. Can anyone help?
Follow the code:
DELIMITER $$
CREATE TRIGGER log_update
AFTER UPDATE ON animais
FOR EACH ROW
IF ( OLD.nome_animal <> NEW.nome_animal) THEN
INSERT INTO log_animais(codigo, momento, ocorrencia) VALUES ( OLD.cod_animal, now(), OLD.nome_animal )
END
$$
DELIMITER ;
When I put the BEGIN, END and/or END IF it also error.
is that, I put so too, and so also of the error in the END. If you put the DEMILITER of the most error yet. No
– Luan Araujo
@Luanaraujo What was the exact error? I tested this exactly on Mariadb and it worked normally.
– Inkeliz
"#1064 - You have an error in your SQL syntax; check the manual that Corresponds to your Mariadb server version for the right syntax to use near '' at line 11" Finally I got it like this: DELIMITER $$ CREATE TRIGGER log_update AFTER UPDATE ON animals FOR EACH ROW BEGIN IF(OLD.animal name_name <> NEW.animal) THEN INSERT INTO log_animals (codigo, moment, occurrence) VALUES (OLD.cod_animal, now(), OLD.animal name_name); END IF; END; $$ ; DELIMITER ; The strange thing was that the red X appeared on the code side, as it was wrong. But thank you so much for the strength @Inkeliz !
– Luan Araujo