0

I receive this message "#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 6" but can not figure out what is wrong.

(position and points are MEDIUMINT, they are not primary key neither unique)

Anyone?

CREATE TRIGGER pointsAssigns
before INSERT ON MyTable
    FOR EACH ROW
BEGIN
IF NEW.position>6 THEN
    set NEW.points=5;
END IF;
END;
2
  • Add an END; as the last line.Also do you use a DELIMITER? Commented Jan 1, 2015 at 18:09
  • I tried both but does not work..The error should be in the '5'. Commented Jan 1, 2015 at 18:13

1 Answer 1

1

As @Mihai mentioned either add closing END and change the DELIMITER

DELIMITER //
CREATE TRIGGER pointsAssigns
BEFORE INSERT ON MyTable
FOR EACH ROW
BEGIN
  IF NEW.position > 6 THEN
    SET NEW.points = 5;
  END IF;
END //
DELIMITER ;

Here is a SQLFiddle demo

or make it one-line trigger and then you don't need neither BEGIN...END block nor changing the DELIMITER

CREATE TRIGGER pointsAssigns
BEFORE INSERT ON MyTable
FOR EACH ROW
  SET NEW.points = IF(NEW.position > 6, 5, NEW.points);

Here is a SQLFiddle demo

Sign up to request clarification or add additional context in comments.

1 Comment

I have tried it before, but only NOW it seems to work..THNAK YOU

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.