CREATE TRIGGER question_preserver BEFORE UPDATE ON bank
FOR EACH ROW
BEGIN
IF TRIM(NEW.question) != TRIM(OLD.question) THEN
INSERT INTO bank_question_history (id,old_question) VALUES (OLD.id,OLD.question)$$
END IF$$
END$$
I am inserting that query into Mysql using PHPMyAdmin's SQL window, using a delim of $$. I get an error 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 5
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 5
I'm sure it's something obvious and I'm just missing it, but no matter what I try I can't get it to work. The error is not helpful at all, and from what I have researched I am doing this exactly like 4-5 examples I found.
Any help would be greatly appreciated, thank you!
Go figure I figured it out right after asking.
CREATE TRIGGER question_preserver BEFORE UPDATE ON bank
FOR EACH ROW
BEGIN
IF TRIM(NEW.question) != TRIM(OLD.question) THEN
INSERT INTO bank_question_history (id,old_question) VALUES (OLD.`id`,OLD.`question`);
END IF;
END$$
You have to use ;
to break each statement/command and your delim $$
to end the entire trigger.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.