Can't update table 'test_trigger' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
[Err] 1442 - Can't update table 'test_trigger' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
DROP TABLE IF EXISTS `test_trigger`;
CREATE TABLE `test_trigger` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`jb` double DEFAULT NULL,
`name` varchar(255) DEFAULT NULL,
`dtype` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
DROP TRIGGER IF EXISTS `t_trigger`;
DELIMITER ;;
CREATE TRIGGER `t_trigger` BEFORE INSERT ON `test_trigger` FOR EACH ROW BEGIN
-- sum jb.. IF new.dtype = 'touch' THEN
-- get sum row id
SET @tmp_id = NULL ; SELECT
MAX(id) INTO @tmp_id
FROM
test_trigger
WHERE
`name` = NEW.`name`
AND dtype = 'sum' ; -- insert or update row IF @tmp_id IS NULL THEN
insert into test_trigger (jb,dtype) values( new.jb ,'sum') ;
ELSE
UPDATE test_trigger SET jb = jb +new.jb WHERE id = @tmp_id;
END IF; END
IF ; END
;;
DELIMITER ;
[Err] 1442 - Can't update table 'test_trigger' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
导致原因是
在一张表中的触发器,不能直接对同一张表执行 增加,删除,修改操作,防止造成死循环(个人理解)。
借助连接查询语句试试看,实现思路,先将要符合删除条件的记录查询出来,作为一个新的集合(相当于一张中间表),在通过集合与当前表的 inner join 语句 进行删除 (记得之前用过,好像可以,记得不是很清楚了)
Can't update table 'test_trigger' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.的更多相关文章
- Can’t update table ‘xxx’ in stored function/trigger because it is already used by statement which invoked this stored function/trigger
MySQL: Solution for ERROR 1442 (HY000): Can't update table 'xxx' in stored function/trigger because ...
- ERROR 1442 (HY000):because it is already used by statement which invoked this stored function/tr
看到mysql的触发器,随手写了一个: mysql> create trigger t_ai_test -> after insert on test -> for each row ...
- MySQL - 问题集 - 触发器更新本表数据异常"Can’t update table ‘tbl’ in stored function/trigger because it is already used by statement which invoked this"
如果你在触发器里面对刚刚插入的数据进行了 insert/update, 则出现这个问题.因为会造成循环的调用. create trigger test before update on test fo ...
- MySql Error: Can't update table in stored function/trigger
MySql Error: Can't update table in stored function/trigger because it is already used by statement w ...
- MySQL触发器更新本表数据异常:Can't update table 'tbl' in stored function/trigger because it
MySQL触发器更新本表数据异常:Can't update table 'tbl' in stored function/trigger because it 博客分类: 数据库 MySQLJava ...
- LLBLGen update table with join
Table1 id Name 1 xxx 2 ooo Table2 Table1Id Table1Name Column1 Column2 Column3 1 sss xxxx xxxx xxxx 2 ...
- 【sql技巧】mysql修改时,动态指定要修改的字段 update `table` set (case when ....) = 1 where id = xx
如果你点进了这篇帖子,那么你一定遇到了跟我一样的问题.别看题目的set case when...,我一开始也是第一反应是用case when但是发现并不好使. 问题呢,说得高大上一点:动态指定要修改的 ...
- 关于Mysql 触发器
首先,测试版本 Mysql 5.6. 然后再看触发器的语法 CREATE [DEFINER = { user | CURRENT_USER }] TRIGGER trigger_name trigge ...
- 对数据库触发器new和old的理解
在数据库的触发器中经常会用到更新前的值和更新后的值,所有要理解new和old的作用很重要.当时我有个情况是这样的:我要插入一行数据,在行要去其他表中获得一个单价,然后和这行的数据进行相乘的到总金额,将 ...
随机推荐
- jQuer中 height scrollTop
jQuery(window).height()代表了当前可见区域的大小,而jQuery(document).height()则代表了整个文档的高度,可视具体情况使用. 注意当浏览器窗口大小改变时(如最 ...
- 使用strtotime和mktime时参数为0时返回1999-11-30的时间戳问题
先看例子 代码如下 复制代码 <?php $time = date('Y-m-d',strtotime('00-00-00 00:00:00')); echo $time; //输出 1999- ...
- C# Ajax 手机发送短信验证码 校验验证码 菜鸟级别实现方法
1.Ajax请求处理页面: using System; using System.Collections.Generic; using System.Linq; using System.Web; u ...
- [TimusACM][1258]程序员撞墙的问题
(本文是从我的旧博客迁移过来的) 问题地址:http://acm.timus.ru/problem.aspx?space=1&num=1258 前几日在博客园看到这种在线测试的时候,有一种相见 ...
- dataset 和DataTable的用法
以下包含了这两种不同属性的用法: foreach (DataRow dr in dataset.Tables[0].Rows) { if (i != 0 && l ...
- 移动端边框1px的实现
查看京东的移动端1px实现原理,用的是:after和css3的scale(0.5)缩放. border-right fr:after{ height:100%; content:' '; width: ...
- Spring Security (Acegi)的登陆配置
简短记录一下: 在authenticationProcessingFilter这个bean中,如果没有配置<property name="alwaysUseDefaultTargetU ...
- VC 2010下安装OpenCV2.4.4
说明: 安装平台:32位XP,VS2010: OpenCV 2.4.4不支持VC 6.0: 网上有很多用CMake编译OpenCV的安装教程,这里建议先不要自己编译,如果使用预编译好的库有问题,再尝试 ...
- [DevExpress]ChartControl之时间轴示例
关键代码: using System; using System.Data; using System.Windows.Forms; using DevExpress.XtraCharts; name ...
- eclipse juno版本中没用 ant
下载了谷歌提供的Android集成开发工具ADT,里面封装了Eclipse,但是很奇怪的是竟然没有Ant插件在里面 标准的Eclipse一般都是内置集成了Ant的. 然后到eclipse的plugin ...