mic-kul
mic-kul

Reputation: 1009

MySQL CREATE TRIGGER, Syntax Error. What I'm doing wrong?

 DELIMITER ||
CREATE TRIGGER `monthly_insert` BEFORE INSERT ON `history_monthly`
FOR EACH ROW
BEGIN
    NEW.`uid` = CONCAT(OLD.`year`, OLD.`month`, OLD.`charactersId`);
END;
||
DELIMITER ;

And it returns an error:

#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 '.`uid` = CONCAT(OLD.`year`, OLD.`month`, OLD.`charactersId`);
END' at line 4 

It's my first time with triggers and I was doing my best to try to find soultion but I failed ;<

Upvotes: 1

Views: 500

Answers (1)

Ike Walker
Ike Walker

Reputation: 65567

You need to add the word SET in this line:

SET NEW.`uid` = CONCAT(OLD.`year`, OLD.`month`, OLD.`charactersId`);

Also, as the commenter pointed out, there is no OLD value in a BEFORE INSERT trigger.

Upvotes: 1

Related Questions