对不同的表使用相同的触发器 [英] use same trigger for different tables
问题描述
我试图在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 ONX
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屋!