我得到了以下兩個觸發器,每個觸發器都獨自工作,但它們不在一起。兩個觸發器,我在更新表時遇到錯誤
我該如何讓他們一起工作?他們更新表中的不同字段。
觸發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 增加了新的answear的問題。
如果我想要做這樣的事情:
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
任何人都可以幫助我嗎?
這工作,謝謝 – trinny