In my schema I have many tables with common fields that I need to fill. This are basicaly control fields like this ones:
id_db_user
date_creation
date_last_update
I have done two triggers to fill this fields:
-- Trigger DDL Statements
delimiter |
CREATE TRIGGER control_insert BEFORE INSERT ON EZT_SOCIETIES
FOR EACH ROW BEGIN
SET NEW.id_db_user = current_user;
SET NEW.date_creation = current_timestamp;
END;
| delimiter ;
delimiter |
CREATE TRIGGER control_update BEFORE UPDATE ON EZT_SOCIETIES
FOR EACH ROW BEGIN
SET NEW.date_last_update = current_timestamp;
END;
| delimiter ;
My question is: Can I write some function to call the operations inside the trigger? Something like this:
function fn_control_insert
SET NEW.id_db_user = current_user;
SET NEW.date_creation = current_timestamp;
and then call this function in the trigger like:
delimiter |
CREATE TRIGGER control_insert BEFORE INSERT ON EZT_SOCIETIES
FOR EACH ROW BEGIN
call fn_control_insert;
END;
| delimiter ;
This is possible to do in MySQL?
Best Regards,