1

我正在尝试在 mysql 触发器中执行以下语句(通过 phpmyadmin)

FOR EACH ROW BEGIN
DELETE from balancetable WHERE triggeredby="salesinvoices" AND invoiceNumber=NEW.invoiceNumber;

INSERT INTO balancetable SET invoiceNumber=NEW.invoiceNumber,ledgerId=NEW.buyerId,date=NEW.invoiceDate,company=NEW.companyId,type="debit",triggeredby="salesinvoices";
END;

我收到此错误:

MySQL said: #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 'FOR EACH ROW BEGIN DELETE from balancetable WHERE triggeredby="salesinvoices" A' at line 1

从上一小时开始,我一直在努力解决这个问题。请指出我的愚蠢:)

在此处输入图像描述

4

1 回答 1

0

您必须命名您的触发器并定义何时应该触发它:

delimiter |
CREATE TRIGGER `some_name` AFTER UPDATE ON `salesinvoices`
FOR EACH ROW BEGIN
    DELETE from balancetable 
    WHERE triggeredby="salesinvoices" 
    AND invoiceNumber=NEW.invoiceNumber;

    INSERT INTO balancetable SET        
          invoiceNumber=NEW.invoiceNumber,
          ledgerId=NEW.buyerId,
          date=NEW.invoiceDate,
          company=NEW.companyId,
          type="debit",
          triggeredby="salesinvoices";
END;
| 
delimiter ;
于 2013-06-01T09:53:44.850 回答