Reputation: 3812
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 :
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
Upvotes: 14
Views: 29565
Reputation: 29759
Can I have a single trigger for multiple tables in MySQL?
No.
But multiple triggers could invoke the same stored procedure.
Upvotes: 21