I created this trigger to insert the value of the calculated value into a field in the table if the user forgets to put the data themselves:
DELIMITER // CREATE TRIGGER OnNewTableRegistry BEFORE INSERT ON eduardo8_plataforma.tabela FOR EACH ROW BEGIN IF NEW.ut = null THEN SET NEW.ut = GetUT('tabela'); ELSEIF NEW.ut = '' THEN SET NEW.ut = GetUT('tabela'); END IF; END; // DELIMITER ;
But I need to do the same with every table in this database. Is it possible to use the same trigger for all tables, and if YES, how do we get the name of the table that caused its use on lines 6 and 8, where tabela is tabela ?
I need something like this:
DELIMITER // CREATE TRIGGER OnNewTableRegistry BEFORE INSERT ON (* as _TableName) FOR EACH ROW BEGIN IF NEW._TableName.ut = null THEN SET NEW._TableName.ut = GetUT(_TableName); ELSEIF NEW._TableName.ut = '' THEN SET NEW._TableName.ut = GetUT(_TableName); END IF; END; // DELIMITER ;
source share