1

I receive the following error when below MySQL statements are executed:

1064 - You have an error in your SQL syntax;

Can anyone explain the error ?

CREATE TRIGGER `before_quiz_attempt_delete` BEFORE DELETE ON `Quiz_Attempt`    
FOR EACH ROW 
BEGIN 
INSERT INTO Quiz_Attempt_History (Q_Code, S_Email, Result)
     VALUES (old.Q_Code, old.S_Email, old.Result);  
UPDATE Quiz_Attempt_History QAH 
     SET QAH.C_Code = (SELECT C_Code FROM Quiz_Scope WHERE Q_Code = old.Q_Code), 
         QAH.S_No =   (SELECT S_No FROM Quiz_Scope WHERE Q_Code = old.Q_Code) 
     WHERE QAH.Q_Code=old.Q_Code AND QAH.S_Email=old.S_Email;   
END;
  • Did you change the delimiter? – Jehad Keriaki Nov 6 '15 at 14:31
2

try this:

delimiter //
CREATE TRIGGER `before_quiz_attempt_delete` BEFORE DELETE ON `Quiz_Attempt`    
FOR EACH ROW 
BEGIN 
INSERT INTO Quiz_Attempt_History (Q_Code, S_Email, Result)
     VALUES (old.Q_Code, old.S_Email, old.Result);  
UPDATE Quiz_Attempt_History QAH 
     SET QAH.C_Code = (SELECT C_Code FROM Quiz_Scope WHERE Q_Code = old.Q_Code), 
         QAH.S_No =   (SELECT S_No FROM Quiz_Scope WHERE Q_Code = old.Q_Code) 
     WHERE QAH.Q_Code=old.Q_Code AND QAH.S_Email=old.S_Email;   
END//
delimiter ;
  • 1
    That will generated the error again because END;// should be END //. – RolandoMySQLDBA Nov 6 '15 at 17:45
  • The code is working fine now. Thanks for the answer. – Umair Nov 7 '15 at 4:08

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