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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. mysql - ERROR 1114 (HY000): The table is full

    mysql - ERROR 1114 (HY000): The table is full - Stack Overflowhttps://stackoverflow.com/questions/73 ...

  5. 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 ...

  6. 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 ...

  7. MySQL Error Handling in Stored Procedures 2

    Summary: this tutorial shows you how to use MySQL handler to handle exceptions or errors encountered ...

  8. ERROR 1114 (HY000): The table 'adv_date_tmp' is full(Mysql临时表应用)

    场景:需要对现在数据库的数据进行批量的进行is_del=1的操作,但是遇到一个问题,在执行sql的时候发现sql不能在查询特定表的时候再嵌套查询来做update的操作,经过讨论,后续我们想到用临时表的 ...

  9. MySQL Error Handling in Stored Procedures---转载

    This tutorial shows you how to use MySQL handler to handle exceptions or errors encountered in store ...

随机推荐

  1. SQL Server查看表信息

    1. sp_spaceused 计算数据和索引使用的磁盘空间量以及当前数据库中的表所使用的磁盘空间量.如果没有给定 objname,sp_spaceused 则报告整个当前数据库所使用的空间. 语法 ...

  2. DOS批处理命令-注释

    注释是每个程序中不可或缺的(不是对计算机来说,而是对我们这些程序员阅读代码来说) 语法: ①rem 这是批处理的注释命令,rem后面的内容全部是注释 例:rem 这是一行注释 ②:: 批处理遇到以冒号 ...

  3. SQL server经典电子书、工具和视频教程汇总

    SQL server经典电子书.工具和视频教程汇总 SQL server经典电子书.工具和视频教程汇总 SQL Server是高校计算机专业的一门必修课程,同时众多企业采用SQL Server作为数据 ...

  4. 在SQL 2012中使用和Oracle 一样的序列

    使用过Oracle的都知道,Oracle中的自增是靠序列来完成的,在一定程度上蛮方便的.现在SQL 2012中也有序列了.来看看怎么做的吧! SQL Server 现在将序列当成一个对象来实现,创建一 ...

  5. ASP.NET MVC 过滤器开发与使用

    ASP.NET MVC 中给我们提供了内置的过滤器,通过过滤器,我们可以在控制器内的方法前后,添加必须的业务逻辑,如权限验证,身份验证,错误处理等. 今天,我们主要介绍3个过滤器:OutputCach ...

  6. PHP 反射 ReflectionClass

    今天遇到了这样一个问题,如下代码: classA.php <?php class ClassA{ public function funcAa(){ } public function func ...

  7. 使用WebJar管理css、JavaScript文件

    Web前端使用了越来越多的JS或CSS,如jQuery, Backbone.js 和Bootstrap.一般情况下,我们是将这些Web资源拷贝到Java的目录下,通过手工进行管理,这种通方式容易导致文 ...

  8. C#基础(八)——C#数据类型的转换

    C#数据类型的转换主要有以下几种方式: 1.强制转换 注意:char类型不能强制转换成int,如果使用强制转化,得到的是原整数的ASCII码值. 2.class.parse(string类型的变量), ...

  9. 【SQLite】使用事务处理带参数的插入

    using (SQLiteConnection conn = new SQLiteConnection(String.Format("Data Source={0};Pooling=true ...

  10. 获取JAVA对象占用的内存大小

    介绍两种获取JAVA对象内存大小的方法. 第一种:Instrumentation 简介: 使用java.lang.instrument 的Instrumentation来获取一个对象的内存大小.利用I ...