MySQL社区

 找回密码
 注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

搜索
查看: 6729|回复: 4
打印 上一主题 下一主题

建立mysql触发器无法触发本表(急)

[复制链接]
跳转到指定楼层
1#
发表于 2007-11-13 13:52:31 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
我在REHT5上安装的mysql5.0.4版,建立触发器如下:

create trigger mailbox_update after update on mailbox for each row update mailbox set password=NEW.password where uid=NEW.uid and  password<>NEW.password;

我的mailbox表中会有两行数据的uid列值是一样的,建立这个触发器用来,当其中一行的值password变化时,同时更改另一个同名列的password值与变化的列值相同,在mysql里建立触发器不提示错误,但一执行更新mailbox表就提示如下信息:

1442   (HY000):   Can't   update   table   'mailbox'   in   stored   function/trigger   because   it   is   already   used   by   statement   which   invoked   this   stored   function/   trigger.

这是何故,是 mysql的触发器不能触发本表吗?  
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
收藏收藏 分享淘帖 顶 踩
2#
发表于 2007-11-13 14:32:49 | 只看该作者
你是怎样更新的?
3#
 楼主| 发表于 2007-11-13 14:36:21 | 只看该作者
update mailbox set password='444'  where username='yuan';

我这个表中有一列名为username,就使用正常的更新表数据命令。在mysql的操作符下执行的。执行之后,表mailbox 中的password列的值变为444,但相应的触发器未执行,报错,信息如上。

[ 本帖最后由 sniper 于 2007-11-13 14:37 编辑 ]
4#
发表于 2007-11-13 23:01:18 | 只看该作者
你的建表SQL,带上几个数据最好.

不过问题有进展,对错误的大致解释:
·  错误:1442 SQLSTATE: HY000 (ER_CANT_UPDATE_USED_TABLE_IN_SF_OR_TRG)
消息:由于它已被调用了该存储函数/触发程序的语句使用,不能在存储函数/触发程序中更新表'%s'。

这种情况应该是尽量避免的。
A more helpful title for this bug might be "Cannot join against trigger table while
modifying another table in a trigger."

trigger limitations that one can not select from the table on which the trigger is firing from within that trigger.

应该是MySQL Trigger的limitations:
in function or trigger you should not modify table which is modified or JUST READ by statement (or by any statement from the chain of statements) that invoke this function or trigger.

激活触发程序时,对于触发程序引用的所有OLD和NEW列,需要具有SELECT权限,对于作为SET赋值目标的所有NEW列,需要具有UPDATE权限。

注释:目前,触发程序不会被级联的 外键动作激活。该限制将会被尽早放宽。
5#
 楼主| 发表于 2007-11-14 09:16:02 | 只看该作者
收到,谢谢!!看来mysql还是须待进一步完善。sybase中,trigger和update是一个事务,一起执行后再提交,但是mysql中,即使不能执行trigger,也会执行update,这也应该是一个bug!!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|申请友链|小黑屋|Archiver|手机版|MySQL社区 ( 京ICP备07012489号   
联系人:周生; 联系电话:13911732319

GMT+8, 2024-5-6 02:31 , Processed in 0.068827 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表