如何在MySQL触发器中修复此IF-ELSE-THEN语句

时间:2011-12-06 09:40:35

标签: mysql sql database triggers

  

可能重复:
  How to fix this MySQL trigger?

CREATE TRIGGER Transaction_insert BEFORE INSERT ON Transaction
FOR EACH ROW
IF Account.CreditBalance + NEW.Amount < Account.CreditLimit WHERE Number = NEW.AccountNumber THEN
UPDATE Account SET CreditBalance = CreditBalance + NEW.Amount where Number = NEW.AccountNumber;
ELSE
SET NEW.Valid = 0
END IF; 

我从phpMyAdmin收到此错误消息。

enter image description here

1 个答案:

答案 0 :(得分:2)

这是If语句的正确语法。

IF search_condition THEN statement_list
    [ELSEIF search_condition THEN statement_list] ...
    [ELSE statement_list]
END IF

你不能在那个地方拥有Where条款!