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
SQL Server allows multiple triggers on the table for the same event and there is no defined order of execution of these triggers. We can set the order of a trigger to either first or last using procedure sp_settriggerorder. There can be only one first or last trigger for each statement on a table.
MySQL triggers fire depending on the activation time and the event for a total of six unique trigger combinations.
Actually, you can't update multiple tables in one statement. After UPDATE operation, a trigger on that table fires up. Secondly, when AFTER UPDATE trigger fires up, SQL Server stores records in two special tables: inserted and deleted. The inserted table stores copies of the affected rows after INSERT and UPDATE.
Only one INSTEAD OF trigger is allowed for each event type (INSERT, UPDATE, or DELETE) per table. If a table has a BEFORE trigger, it cannot have an INSTEAD OF trigger. The reverse is also true. If a table has an INSTEAD OF X trigger, AFTER X triggers defined for that table will not fire (where X is an event type).
Can I have a single trigger for multiple tables in MySQL?
No.
But multiple triggers could invoke the same stored procedure.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With