简体   繁体   English

MySQL触发器执行插入和更新

[英]MySQL Trigger perform insert and update

I have a MySQL after insert trigger that inserts values from an inventory table into an inventory audit table and this works fine. 在插入触发器之后,我有一个MySQL,该触发器将库存表中的值插入库存审计表中,并且工作正常。 I need to add another step to the trigger and not having much luck. 我需要向触发器添加另一个步骤,但运气不佳。 In addition to the insert into the audit table, in the original table, I need to update a column 'createdby' with the value from 'modifiedby'. 除了插入到审计表中之外,在原始表中,我还需要使用“ modifiedby”中的值更新“ createdby”列。

Here is the trigger that works. 这是有效的触发器。 I'm hoping someone can help me modify this to add the update. 我希望有人可以帮助我进行修改以添加更新。

CREATE TRIGGER mtenclosures.inventory__ai AFTER INSERT ON mtenclosures.inventory FOR EACH ROW
INSERT INTO mtenclosures.inventory_archive SELECT 'insert', NULL, NOW(), d.* 
FROM mtenclosures.inventory AS d WHERE d.id = NEW.id;

Thanks, David 谢谢大卫

Try 尝试

CREATE TRIGGER mtenclosures.inventory__ai AFTER INSERT ON mtenclosures.inventory
FOREACH ROW
INSERT INTO mtenclosures.inventory_archive(/column names of mt.inventory_archive)
VALUES(
SELECT 'insert', NULL, NOW(), d.* 
FROM mtenclosures.inventory AS d WHERE d.id = NEW.id;);

This should work. 这应该工作。

Hoe this helps.... this这有帮助...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM