0
CREATE TRIGGER updateNewEmp
AFTER UPDATE ON BasicDetails
FOR EACH ROW  BEGIN
    if(NEW.MiddleName<>OLD.MiddleName) then
      insert into BasicDetails_audit(MiddleName,`State`,Country,Community) 
      VALUES(NEW.MiddleName,NEW.`State`,NEW.Country,NEW.Community)
end if;
end

It throws a syntax error near the END IF statement. Can anyone please help?

2
  • Semicolon after INSERT query is lost. PS. Rewrite the query and move the condition from IF to WHERE clause of INSERT query. PPS. Your data saved by a trigger do not allow to distinguish what record was altered... – Akina Jan 4 '19 at 19:36
-1

You have to change DELIMITER to something else than ;

DELIMITER $$
CREATE TRIGGER updateNewEmp AFTER UPDATE ON BasicDetails FOR EACH ROW  
BEGIN
  IF(NEW.MiddleName<>OLD.MiddleName) 
  THEN
    INSERT INTO BasicDetails_audit(MiddleName,`State`,Country,Community) 
         VALUES (NEW.MiddleName,NEW.`State`,NEW.Country,NEW.Community);
  END IF;
END$$
DELIMITER ;
1
  • And missing some semicolons. – Rick James Jan 4 '19 at 21:32

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.