我正在尝试创建一个触发器,在一个表上插入更新另一个表。这是我的SQL查询:
CREATE TRIGGER makePayment AFTER INSERT ON Payments FOR EACH ROW
BEGIN
UPDATE Invoice
SET InvoiceClientPaid = SUM(InvoiceClientPaid + NEW.PaymentAmt)
WHERE InvoiceID = NEW.PaymentInvoiceID;
END;
无论我做什么,我都会收到以下错误:
Error Code: 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
我不认为它与SUM有关,因为在SET命令上尝试basic = 1会给出确切的错误。第6行没有''非常令人困惑?
答案 0 :(得分:0)
如果您直接将此查询输入MySQL,则需要在查询之前使用(例如)UPDATE
更改分隔符,否则它会认为查询在END
处结束''
声明的结尾。 MySQL然后看到DELIMITER //
CREATE TRIGGER makePayment AFTER INSERT ON Payments FOR EACH ROW
BEGIN
UPDATE Invoice
SET InvoiceClientPaid = SUM(InvoiceClientPaid + NEW.PaymentAmt)
WHERE InvoiceID = NEW.PaymentInvoiceID;
END; //
DELIMITER ;
之前没有任何内容,并且抱怨什么都没有({{1}})。所以试试这个:
{{1}}