-2

I'm creating a trigger in mysql, but even with the correct syntax and the query being accepted the trigger is not created. If anyone can help. The following is the sql:

DELIMITER $

CREATE TRIGGER Data_entrada AFTER UPDATE ON scadabr.aux_Batelada FOR EACH ROW
BEGIN
   if OLD.flag_entrada=0 AND NEW.flag_entrada=1 THEN
    UPDATE scadabr.aux_Batelada SET dtEntrada=NOW() where idBatelada = 1;
end if;
END;

DELIMITER ;
  • 3
    This is an English-language site, please post in English to ensure people can understand what you're asking. Alternatively, consider posting your question on the Portuguese-language site – mustaccio Jul 25 '18 at 19:58
  • FYI - As noted above, your direct communications on this site should be in English. However, many people do post code where the column and variables names are non-English. Don't try to rewrite those in English, as you may introduce typos and other issues not existing in your actual code. – RDFozz Jul 25 '18 at 22:18
  • What is the error message? Qual é a mensagem de erro? Please edit your question and add the message. Por favor, edite sua pergunta e adicione a mensagem. – John aka hot2use Jul 26 '18 at 10:53
  • You change the delimiter to $, but don't use it anywhere. – mustaccio Jul 26 '18 at 12:42
  • If it is the new row that you want to update, use a before trigger. As @mustaccio points out, replace END; with END$ – Lennart Jul 26 '18 at 13:45
0
CREATE TRIGGER Data_entrada AFTER UPDATE ON scadabr.aux_Batelada
FOR EACH ROW BEGIN
   if OLD.flag_entrada=0 AND NEW.flag_entrada=1 THEN
    UPDATE scadabr.aux_Batelada SET dtEntrada=NOW() where idBatelada = 1;
end if;
END;

-->

CREATE TRIGGER Data_entrada   BEFORE   UPDATE ON scadabr.aux_Batelada
FOR EACH ROW BEGIN
    if OLD.flag_entrada=0 AND NEW.flag_entrada=1 THEN
        SET NEW.dtEntrada=NOW(), NEW.idBatelada = 1;
    end if;
END;
  • ??? What do you want to obtain when you change NEW pseudotable data in AFTER UPDATE trigger? all changes wiil be ignored. Rewrite the whole trigger and change the firing condition to BEFORE UPDATE. – Akina Jul 26 '18 at 4:44
  • @Akina - Good point. Does my change look correct now? – Rick James Aug 16 '18 at 22:57
  • Yes, now it is correct. – Akina Aug 17 '18 at 4:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.