如果想插入数据,先设置主键,再依次设置其他属性值的时候,在你输入完主键,navicat执行insert操作
当你输入其他的时候,语句就变成了update,当然这期间没有点保存。所以写的触发器就一直失效。这是一个插入后生效的触发器。(因为一直在执行update操作)
如果你不设置主键,再依次设置其他属性值的时候,就会是insert操作,如下图。
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
再说说同一个条件写触发器,触发多个操作:
触发器内容:
#type =2 全场竞猜 对应 flow 表中的type = 2 消费 category = 51 竞猜支出
Begin
#获取字典表的下注标识A or B
SET @a_describe =(select a_describe from g_guess_describe where dict_id = new.dict_id);
if
new.category = 2 then
#插入流水
insert into c_u_f_order_flow(flow_id, cuuid,type,category, order_id, coins, create_time) values(null,new.cuuid,2,51,new.order_id,new.price,NOW());
#更新参与人数
UPDATE g_guess_info SET join_count = join_count +1 WHERE guess_id = new.guess_id;
#更新奖金池数量
if new.winning_team = @a_describe then
UPDATE g_guess_info SET a_bonus_pool =a_bonus_pool +new.price WHERE guess_id = new.guess_id;
else
UPDATE g_guess_info SET b_bonus_pool =b_bonus_pool +new.price WHERE guess_id = new.guess_id;
end if;
end if;
end