Reputation: 9094
I have created this trigger to insert a value calculated value to a field in the table in case the user forget to put the data himself:
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 that database. Is it possible to use the same trigger to all the tables and if YES, how do we get the name of the table that triggered to use it in the line 6 and 8 where there is tabela
specified?
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 ;
Upvotes: 5
Views: 7175
Reputation: 425003
No. The syntax doesn't provide for it.
It makes no sense to allow it, because the NEW keyword must refer to a particular row definition. If you have two tables with the same row definition, they should be made into the one table, with another column denoting the difference.
Upvotes: 3