我们可以在MySQL中为多个表提供单个触发器

时间:2023-01-01 15:23:51

Can I have a single trigger for multiple tables in MySQL? I have to perform same task after inserting either of the table_1 or table_2 e.g :

我可以在MySQL中为多个表创建一个触发器吗?插入table_1或table_2之后我必须执行相同的任务,例如:

CREATE TRIGGER trigger-1_4_task1
   AFTER INSERT ON `table_1`
   FOR EACH ROW
   BEGIN
    .....task1
   END //

CREATE TRIGGER trigger-2_4_task1
   AFTER INSERT ON `table_2`
   FOR EACH ROW
   BEGIN
     .... same task as task1
   END //

Can I combine two above trigger like:

我可以将以上两个触发器组合起来:

CREATE TRIGGER trigger_4_task1
   AFTER INSERT ON `table_1` OR `table_2`
   FOR EACH ROW
     BEGIN
      ..... task1
     END//

Thanks

谢谢

1 个解决方案

#1


14  

Can I have a single trigger for multiple tables in MySQL?

我可以在MySQL中为多个表创建一个触发器吗?

No.

没有。

But multiple triggers could invoke the same stored procedure.

但是多个触发器可以调用相同的存储过程。

#1


14  

Can I have a single trigger for multiple tables in MySQL?

我可以在MySQL中为多个表创建一个触发器吗?

No.

没有。

But multiple triggers could invoke the same stored procedure.

但是多个触发器可以调用相同的存储过程。