mysql 删除一行 成功触发,在mysql中通过触发器删除插入表中的同一行

I'm trying to remove a row after inserted in a temp table and I get this error:

INSERT INTO `temp_program_counter` (`id`, `program_id`) values (NULL, '275')

Can't update table 'temp_program_counter' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.

And here is my trigger:

DELIMITER $$

DROP TRIGGER IF EXISTS `testtemp`$$

CREATE

TRIGGER `testtemp` AFTER INSERT ON `temp_program_counter`

FOR EACH ROW BEGIN

UPDATE `program` SET `view_count`=`view_count`+1;

DELETE FROM `temp_program_counter` WHERE id=new.id;

END;

$$

DELIMITER ;

this table is a temp table that get's data with delay and after receiving must update the main table and be deleted from temp.

thanks for helping in advance.

解决方案

You probably have already resolved this in some way but I'll post the answer anyway:

You cannot refer to the same table that triggered the trigger in a trigger (or a combination of trigger and stored procedure). This could mean an infinite loop, so sql prevents it by giving that error, resulting in always the same error.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值