我得到了以下两个触发器,每个触发器都单独工作,但它们一起不工作。
我怎样才能让他们一起工作?他们更新表中的不同字段。
触发器1:
create trigger wys_sk_u after update on `things`
for each row
begin
UPDATE `current` s
INNER JOIN things u ON s.id_thing = u.id_thing
INNER JOIN dude_base b ON b.id= s.id
SET s.`curr_cash` = u.cash1 * b.cash2/ 100;
end;
$$
触发器2:
create trigger suma_u after update on `current`
for each row
begin
UPDATE `current`
SET `mysum` = `curr_cash` + `mysum`;
end;
$$
第一个应该更新何时cash1
或cash2
更新,并更改curr_cash
. 其次应该更新时curr_cash
更新,并更改mysum
。
编辑表格内容时出现以下错误:
#1442 - Can't update table 'current' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
@edit 为问题添加了新的答案。
如果我想做这样的事情怎么办:
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
任何人都可以帮我解决这个问题吗?