触发器 - 语法错误#1064新/旧

时间:2012-12-03 17:14:56

标签: mysql

我在这里犯了什么错误?

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

任何人都可以帮我这个吗?

1 个答案:

答案 0 :(得分:4)

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

IF new.`new_pay_date` <> old.`new_pay_date` THEN
    SET new.`total_cash` = new.`curr_cash` + new.`total_cash`;
END IF;