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 which invoked this stored function/trigger
I am running a MySQL Query. But when a new row is added from form input I get this error:
Error:Can't update table 'brandnames' in stored function/trigger because it is
already used by statement which invoked this stored function/trigger.
From the code:
CREATE TRIGGER `capital` AFTER INSERT ON `brandnames`
FOR EACH
ROW UPDATE brandnames
SET bname = CONCAT( UCASE( LEFT( bname,1)), LCASE( SUBSTRING( bname,2)))
What does this error mean?
You cannot change a table while the INSERT trigger is firing. The INSERT might do some locking which could result in a deadlock. Also, updating the table from a trigger would then cause the same trigger to fire again in an infinite recursive loop. Both of these reasons are why MySQL prevents you from doing this.
However, depending on what you're trying to achieve, you can access the new values by using NEW.fieldname or even the old values--if doing an UPDATE--with OLD.
If you had a row named full_brand_name and you wanted to use the first two letters as a short name in the field small_name you could use:
CREATE TRIGGER `capital` BEFORE INSERT ON `brandnames`
FOR EACH ROW BEGIN
SET NEW.short_name = CONCAT(UCASE(LEFT(NEW.full_name,1)), LCASE(SUBSTRING(NEW.full_name,2)))END
The correct syntax is:
FOR EACH ROW SET NEW.bname = CONCAT( UCASE( LEFT( NEW.bname,1)), LCASE( SUBSTRING( NEW.bname,2)))
MySql Error: Can't update table in stored function/trigger的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- mysql - ERROR 1114 (HY000): The table is full
mysql - ERROR 1114 (HY000): The table is full - Stack Overflowhttps://stackoverflow.com/questions/73 ...
- 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 ...
- 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 Error Handling in Stored Procedures 2
Summary: this tutorial shows you how to use MySQL handler to handle exceptions or errors encountered ...
- ERROR 1114 (HY000): The table 'adv_date_tmp' is full(Mysql临时表应用)
场景:需要对现在数据库的数据进行批量的进行is_del=1的操作,但是遇到一个问题,在执行sql的时候发现sql不能在查询特定表的时候再嵌套查询来做update的操作,经过讨论,后续我们想到用临时表的 ...
- MySQL Error Handling in Stored Procedures---转载
This tutorial shows you how to use MySQL handler to handle exceptions or errors encountered in store ...
随机推荐
- 剑指offer_面试题11 数值的整数次方_考察代码的完整性
测试通过代码: package t0825; public class Power { public static void main(String[] args){ System.out.print ...
- android 安装包签名问题探究
1.首先先科普一下,android为什么需要给安装包签名: 所有的Android应用程序在发布之前都要求开发人员用一个证书进行数字签名,anroid系统不会安装没有进行签名的由于程序. 平时我们 ...
- Word 2003 出现 向程序发送命令时出现问题 的 解决方案
这种原因出现的问题是word的模板出现问题. 解决方案是重新让word生成Norma.dot文档. 步骤: 1,按住视窗键+R或者开始菜单搜索文件和程序,粘贴 %appdata%\microsoft\ ...
- java新手笔记29 读取文件
1.读取文件 package com.yfs.javase; import java.io.FileInputStream; import java.io.FileReader; import jav ...
- java进阶一之jdk8新特性
1.官方发布的jdk8新特性 2.51CTO相关专题
- vs工程链接出现error LNK2005...already defined
今天使用vs2008编译工程无错误,链接过程,出现很多这样的错误: error LNK2005: "public: __thiscall std::basic_string<char, ...
- [android]netd与NetworkManagementService初印象
[功能]Netd是什么,主要负责什么功能 为什么这次会接触Netd主要是因为在设置防火墙时候碰到了.关于Netd可以干什么可以从Netd的源码中CommandListener中得到答案.按照我的理解, ...
- 关于C++引用的一些注意点
C++的引用首先跟指针的最大区别就是引用不是一个对象,而指针是一个对象:其次引用在其定义时就要初始化,而指针可以不用. ; int &rval = val; 此时rval就绑定了val,其实就 ...
- javascript实现URL不缓存的方法
<script> document.write("<s"+"cript type='text/javascript' src='/js/test.js? ...
- jquery 获取 CheckBox 的状态
<td style="width:220px;vertical-align:central;"><input type="checkbox" ...