对不同的表使用相同的触发器 [英] use same trigger for different tables

查看:138
本文介绍了对不同的表使用相同的触发器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在MySQL中插入新数据时为不同的表使用相同的触发器名称。
考虑X和Y表。
这两个表都具有created_date列。 >


TRIGGER insert_current_date X 每行设置
NEW.created_date = NOW()


仅允许使用X表。



对于Y表,我还需要相同的触发函数。



是否可以使用单个触发函数?

解决方案

触发器被分配给特定的表,但是,您可以创建一个存储过程,并从触发器中运行该过程。


I'm trying to have same trigger name for different tables while inserting new data in MySQL. Consider X and Y tables. Both tables have created_date column.

Question is, can I have same single trigger function to effect on both tables while inserting into those tables separately.

TRIGGER insert_current_date BEFORE INSERT ON X FOR EACH ROW SET NEW.created_date = NOW( )

This only allow for X table.

For Y table also I need same trigger function.

Is it possible to do with single trigger function?

解决方案

Triggers are assigned to specific tables, however, you could create a stored procedure, and run the procedure from the trigger.

这篇关于对不同的表使用相同的触发器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆