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的作用很重要.当时我有个情况是这样的:我要插入一行数据,在行要去其他表中获得一个单价,然后和这行的数据进行相乘的到总金额,将 ...
随机推荐
- ios之UITableViewController(二) tableView的编辑模式
tableView的编辑模式 表视图可以进入编辑模式,当进入编辑模式就可以进行删除.插入.移动单元等操作 效果图: 让表视图进入编辑模式,进入编辑模式的方法有两种,一种是使用导航栏的edit 按钮,另 ...
- mysql插入表中的中文显示为乱码或问号的解决方法
版权声明:本文为博主原创文章,未经博主允许不得转载. 今天在做ssh的博客项目时发现mysql数据库中的中文显示为问号,网上查阅了很多资料,都不是很全,所以我总结一下,供大家参考和自己复习. 1.我的 ...
- easyUi学习备忘
1.获取datagrid的自身相关的属性方式: jQuery("#grid").datagrid("options").height jQuery(" ...
- [Bootstrap]组件(一)
Glyphicons字体图标 基类.glyphicon {position/top/display/font-family/} 具体类 {content} --表现在伪元素上 使用要点:a.基类 ...
- flume+kafka (分区实现 默认单分区)
这篇文章主要是log4j+flume+kafka的内容 首先从从下面的地址下载flume+kafka的插件包 https://github.com/beyondj2ee/flumeng-kafka-p ...
- HIV T2
甲学者将HIV病毒的遗传物质彻底水解后得到A.B.C三种化合物,乙学者将组成T2噬菌体的遗传物质彻底水解后得到了A.B.D三种化合物.你认为C.D两种化合物分别指的是 A.尿嘧啶.胸腺嘧啶 B.胸腺嘧 ...
- 《C++Primer中文版》读书笔记——第1章 开始
istream对象:cin(标准输入对象); ostream对象:cout(标准输出对象) cerr(输出错误和警告) clog(输出一般性信息) 读取数量不定的输入数据,eg , sum=; whi ...
- 设计main函数退出后继续执行一段代码
原理: 使用 _onexit() 函数注册一个函数,这个函数会在main函数退出后执行 使用原则: 1.包含在cstdlib中,是c语言中的库函数: 2.需要注册的函数格式为:int类型返回值.无参数 ...
- mysql mmm高可用架构设计
项目概述:搭建主从,双主,安装Perl模块 安装配置mmm软件 测试 硬件环境:4台虚拟PC 软件环境:rehl6.5 MySQL-5.6.26 percona-xtrabackup-2.3.4 ...
- 安装apk文件报waiting for device 时解决办法
C:\Users\root>adb install d:\rry_0514.apkerror: more than one device and emulator- waiting for de ...