答案 0 :(得分:1)
CREATE TRIGGER `db`.`trigger_name`
AFTER INSERT ON `table_name` FOR EACH ROW
BEGIN
update table
set status = case when new.balance = 0 then '1' else 0 end;
它将在INSERT期间检查新余额值的值并更新状态。 我希望这会有所帮助。
CREATE TRIGGER `db`.`trigger_name`
AFTER UPDATE ON `table_name` FOR EACH ROW
BEGIN
update table
set status = case when balance = 0 then '1' else 0 end;
答案 1 :(得分:1)
在执行更新之前,使用new
行来访问和更改值。
create trigger mytrigger
before update on mytable
for each row
set new.status = (new.balance = 0);
方便地(在MySQL中),true
为1
,false
为0
。