[英]MYSQL : Getting error in TRIGGER
I want trigger which function is - before update of product table if price value is changed then copy that row to product_log table. 我想触发哪个功能-如果价格值更改,在更新产品表之前,然后将该行复制到product_log表。 I want this functionality to manage log of product price.
我想要此功能来管理产品价格日志。
This is my product table 这是我的产品表
# Name Type
1 id int(11)
2 name varchar(100)
3 price bigint(20)
4 created_date datetime
This is my product_log table 这是我的product_log表
# Name Type
1 id int(11)
2 name varchar(100)
3 price bigint(20)
4 created_date datetime
5 is_procced int(11)
This is my trigger - 这是我的触发器-
CREATE TRIGGER pro_log BEFORE UPDATE ON product
FOR EACH ROW
BEGIN
IF (OLD.price != NEW.price)
THEN
INSERT INTO product_log (SELECT *, 1 FROM product WHERE id = OLD.id);
END IF;
END;
I am getting this error - #1064 - You have an error in your SQL syntax; 我收到此错误- #1064-您的SQL语法有错误; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 6
检查与您的MySQL服务器版本相对应的手册以获取在第6行的''附近使用的正确语法
You need to change the delimiter. 您需要更改定界符。 Otherwise the trigger definition ends at the first semicolon which would make it incomplete.
否则,触发器定义将在第一个分号处结束,这将使其不完整。
delimiter |
CREATE TRIGGER pro_log BEFORE UPDATE ON product
FOR EACH ROW
BEGIN
IF (OLD.price != NEW.price)
THEN
INSERT INTO product_log
SELECT *, 1 FROM product WHERE id = OLD.id;
END IF;
END
|
delimiter ;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.