【发布时间】:2014-09-04 18:41:50
【问题描述】:
我们有 2 个存储用户名和密码的表,以及两个用户登录的网站(我知道这是个坏主意,但我无法控制)。
因此,当成员在一个表上更新他们的密码时,我希望触发器也更新另一个表上的密码。我遇到了问题,因为它给了我一个错误。
查询:
update authenticate set password = md5('superman') where member_id = 108649
错误:
ERROR 1442 (HY000) at line 3: Can't update table 'authenticate' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
这里有两个触发器:
-- When update runs on the authenticate table
CREATE TRIGGER `authenticate_after_update` AFTER UPDATE ON `authenticate` FOR EACH ROW BEGIN
IF new.password != old.password THEN
update auth set passwd = new.password where member_id = new.member_id;
end if;
END
-- When update runs on the auth table
CREATE TRIGGER `auth_after_update` AFTER UPDATE ON `auth` FOR EACH ROW BEGIN
if new.passwd != old.passwd then
update authenticate set password = new.passwd where member_id = new.member_id;
end if;
END
【问题讨论】:
标签: mysql triggers sql-update