gpt4 book ai didi

mysql - 触发器中的更新语法错误

转载 作者:行者123 更新时间:2023-11-29 00:37:22 25 4
gpt4 key购买 nike

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

代码如下:

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 上工作。

最佳答案

试试这个:

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

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

关于mysql - 触发器中的更新语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13683630/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com