我在我的一个数据库的触发器中有这个更新语句:
UPDATE trainees
SET rsi_total = (
SELECT SUM(RsiTotal) as RsiTotal
FROM (
SELECT MAX(hours) as RsiTotal
FROM courses
LEFT JOIN do_not_add ON courses.fk_class_id = do_not_add.fk_class_id
INNER JOIN trainees ON courses.FK_TRAINEES_ID = trainees.PK_TRAINEE_ID
WHERE do_not_add.fk_class_id IS NULL
AND trainees.pk_trainee_id = new.fk_trainees_id
GROUP BY courses.FK_CLASS_ID
) courses
)
WHERE trainees.pk_trainee_id = new.fk_trainees_id
并且完全符合我的期望,最近我将我的数据库迁移到另一台机器并移动并重命名了几个表和列。所以我重写了这个触发器:
UPDATE main
SET rsi_total = (
SELECT SUM(RsiTotal) as RsiTotal
FROM (
SELECT MAX(completed_hrs) as RsiTotal
FROM courses
LEFT JOIN jac.do_not_add ON courses.fk_class_id = do_not_add.fk_class_id
INNER JOIN main ON courses.fk_main_id = main.pk_main_id
WHERE do_not_add.fk_class_id IS NULL
AND main.pk_main_id = new.fk_main_id
GROUP BY courses.FK_CLASS_ID
) courses
)
WHERE main.pk_main_id = new.fk_main_id
但我收到错误1093?我查看了这个错误,它说我无法更新正在更改的表,我不明白为什么旧的触发器继续工作但不是这个新的?
答案 0 :(得分:0)
迁移到另一台计算机,您可能获得了更新版本的MySql,其中优化程序不再接受任何更长的子查询来访问正在更新的同一个表。