触发器中的UPDATE语法错误

时间:2012-12-03 12:49:50

标签: mysql sql syntax triggers

我需要自动使用触发器更新我的列。

这是代码:

create trigger sum update on `cash`
for each row
begin
UPDATE `cash`
SET `sum_cash` = `cash` + `sum_cash`;
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 'update on `cash` for each row begin UPDATE cash` SE' at line 1

我在研究MySQL。

1 个答案:

答案 0 :(得分:1)

试试这个:

delimiter $$
create trigger my_sum after update on `cash`
for each row
begin
UPDATE `cash`
SET `sum_cash` = `cash` + `sum_cash`;
end;
$$

您错过了afterbefore关键字。此外,我更改了触发器名称,因为sum是关键字。