3

我在这里犯了什么错误?

CREATE TRIGGER total BEFORE UPDATE ON `current` FOR EACH ROW
BEGIN
if new.`new_pay_date` <> old.`new_pay_date`
  SET new.`total_cash` = new.`curr_cash` + new.`total_cash`;
end if;
END;
$$

错误:

#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 'SET new.`total_cash` = new.`curr_cash` + new.`total_cash`; end if;' at line 4

这在没有

if new.`new_pay_date` <> old.`new_pay_date`
end if;

但我需要检查这一点,并且只更新日期更改。

当前表:

curr_cash
new_pay_date
id_person
id_thing
total_cash

任何人都可以帮我解决这个问题吗?

4

1 回答 1

4

尝试THEN在 if 语句的末尾添加:

IF new.`new_pay_date` <> old.`new_pay_date` THEN
    SET new.`total_cash` = new.`curr_cash` + new.`total_cash`;
END IF;
于 2012-12-03T17:34:02.337 回答