mysql触发器 重要学习资料:
http://dev.mysql.com/doc/refman/5.1/zh/triggers.html
在使用触发器的时候,遇到一个错误:
[SQL]insert into tb_recharge_records(user_id,pointcoupon_added) values(214983,10);[Err] 1442 - Can't update table 'tb_recharge_records' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
通过查找资料:
http://blog.csdn.net/liuliu20036/article/details/4158891
触发器在插入时更新此条新记录 错误it is already used by statement which invoked this stored functiontrigger的解决方法
SmartB2B 是一款基于PHP、MySQL、Smarty的B2B行业电子商务网站管理系统,系统提供了供求模型、企业模型、产品模型、人才招聘模型、资讯模型等模块,适用于想在行业里取得领先地位的企业快速假设B2B网站,可以运行于Linux与Windows等多重服务器环境,安装方便,使用灵活。 系统使用当前流行的PHP语言开发,以MySQL为数据库,采用B/S架构,MVC模式开发。融入了模型化、模板
0
问题:
create trigger InsertUser
begin
update users
set user_power='[resource]'
where user_id=new.user_id;
end;
当触发器执行过程中出现了错误:我使用的是Mysql5.0
Can't update table 'users' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
请问这里是怎么回事?
解决方法:
如果你在触发器里面对刚刚插入的数据进行了 insert/update, 则出现这个问题。因为会造成循环的调用.
应该使用set操作,而不是在触发器里使用 update,比如
create trigger InsertUser
begin
set new.user_power='[resource]'
end;
另外这里必须在插入之前来执行该触发器。
============
通过触发器 实现添加记录,则自动添加插入时间
set @newid=NEW.recharge_id;
if @newid>0 then
update tb_recharge_records set add_time=now() where recharge_id=@newid and ""="触发器不可调用宿主表";
end if;
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
C++高性能并发应用_C++如何开发性能关键应用
Java AI集成Deep Java Library_Java怎么集成AI模型部署
Golang后端API开发_Golang如何高效开发后端和API
Python异步并发改进_Python异步编程有哪些新改进
C++系统编程内存管理_C++系统编程怎么与Rust竞争内存安全
Java GraalVM原生镜像构建_Java怎么用GraalVM构建高效原生镜像
Python FastAPI异步API开发_Python怎么用FastAPI构建异步API
C++现代C++20/23/26特性_现代C++有哪些新标准特性如modules和coroutines
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号