是否可以将NEW和OLD表从触发器传递到MySQL中的过程中? [英] Is it possible to pass the NEW and the OLD tables from a trigger into a procedure in MySQL?
问题描述
是否可以将NEW和OLD表从触发器传递到MySQL中的过程中? 我怀疑没有,因为没有过程可以接受的表这样的数据类型. 有任何可行的解决方法?
Is it possible to pass the NEW and the OLD tables from a trigger into a procedure in MySQL? I suspect no, since there is no such a datatype as table that a procedure accepts. Any workarounds possible?
理想情况下,它看起来像这样:
Ideally it would look like this:
CREATE TRIGGER Product_log AFTER UPDATE ON Product
FOR EACH ROW BEGIN
call logChanges(OLD, NEW);
END;
推荐答案
这是不可能的,因为没有新的或旧的表.整个触发器与 the 表相关-新"和旧"指的是行及其在之前和之后包含的值触发的事件.换句话说,您的示例将是:
it's not possible because there is no NEW or OLD table. The entire trigger is related to the table - the "new" and "old" refer to the rows and the values they contained before and after the event that was triggered. In other words, your example would be:
call logChanges(OLD.customername, NEW.customername)
您还可以将所有OLD数据保存在历史表中(我希望logchange仍然可以这样做),基本上是生产表的克隆,如下所示:
You could also save all the OLD data in a history table (which I expect logchanges does anyways), basically being a clone of the production table something like this:
BEGIN
IF OLD.customer_name != NEW.customer_name
THEN
INSERT INTO myTable_chagne_history
(
customer_id ,
customer_name ,
another_field ,
edit_time
)
VALUES
(
OLD.customer_id,
OLD.customer_name,
OLD.another_field ,
NEW.time_edit_was_made
);
END IF;
END;
这篇关于是否可以将NEW和OLD表从触发器传递到MySQL中的过程中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!