2013-06-01 47 views
1

我試圖執行在MySQL觸發下面的語句(通過phpmyadmin)錯誤在MySQL

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 

我一直在敲打我的頭從最後一刻開始。指出我的愚蠢PLS :)

enter image description here

+0

既然你已經找到了你的問題的解決方案張貼作爲一個答案這樣別人才能受益。 – peterm

回答

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 ; 
+0

我正在通過phpmyadmin來完成。 – beNerd

+0

你在做什麼? –

+0

通過phpmyadmin在表上添加觸發器。看到我剛剛附加的截圖。 – beNerd