DROP TRIGGER t_afterinsert_on_tab1 ;
CREATE TRIGGER t_afterinsert_on_tab1
AFTER insert ON a
for each row
BEGIN
if exists(select count(*) from a where a.tag_id=new.tag_id) THEN
update testhuanzhuanglie set value=new.temperature where name=new.tag_id;
else
insert into testhuanzhuanglie(NAME,value) values(new.tag_id,new.temperature);
end if;
END

mysql触发器insert一直不被执行
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
3条回答 默认 最新
- 丵鹰 2017-07-13 01:39关注
exists(select count(*) from a where a.tag_id=new.tag_id) 这个结果恒定为true,exists值判断null时为false,而count(*)就是没有数据也是0,
AFTER insert ON a这个要改成before本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报