Is it possible to fire a mysql trigger for both the insert and update events of a table?
I know I can do the following
CREATE TRIGGER my_trigger
AFTER INSERT ON `table`
FOR EACH ROW
BEGIN
.....
END //
CREATE TRIGGER my_trigger
AFTER UPDATE ON `table`
FOR EACH ROW
BEGIN
.....
END //
But how can I do
CREATE TRIGGER my_trigger
AFTER INSERT ON `table` AND
AFTER UPDATE ON `table`
FOR EACH ROW
BEGIN
.....
Is it possible, or do I have to use 2 triggers? The code is the same for both and I don't want to repeat it.
You have to create two triggers, but you can move the common code into a procedure and have them both call the procedure.
In response to @Zxaos request, since we can not have AND/OR operators for MySQL triggers, starting with your code, below is a complete example to achieve the same.
1. Define the INSERT trigger:
2. Define the UPDATE trigger
3. Define the common PROCEDURE used by both these triggers:
You note that I take care to restore the delimiter when I am done with my business defining the triggers and procedure.
unfortunately we can't use in MySQL after INSERT or UPDATE description, like in Oracle