我有以下存储过程
DELIMITER //
CREATE TRIGGER OrderDetail_AFTER_INSERT AFTER INSERT ON OrderDetail
FOR EACH ROW
BEGIN
UPDATE Order SET total = total + NEW.subtotal WHERE id = NEW.orderid;
END;
//
DELIMITER ;
我得到的错误是
ERROR 1064 <4200>: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version fir the right syntax to use ner 'Order SET total = total + NEW.subtotal WHERE id = NEW.orderid; END' at line 5
任何想法?请帮忙
答案 0 :(得分:0)
订单是保留字。请把它放在它周围
DELIMITER //
CREATE TRIGGER OrderDetail_AFTER_INSERT AFTER INSERT ON OrderDetail
FOR EACH ROW
BEGIN
UPDATE `Order` SET total = total + NEW.subtotal WHERE id = NEW.orderid;
END;
//
DELIMITER ;
试一试!!!
答案 1 :(得分:0)
您似乎正在使用&#39;订购&#39;作为表名。在MySql中,&#39; order&#39;是一个保留关键字,因此请避免使用关键字作为表名。 This Link已经在此处报告了类似的错误。因此,请更改表名称的名称&#39;订单&#39;任何其他人或给它一个引用,例如&#39; Order&#39;。
DELIMITER //
CREATE TRIGGER OrderDetail_AFTER_INSERT AFTER INSERT ON OrderDetail
FOR EACH ROW
BEGIN
UPDATE `Order` SET total = total + NEW.subtotal WHERE id = NEW.orderid;
END;
//
DELIMITER ;