If I update person with an empty one that does not insert anything in Audit, but if I update person with a data, name, etc., that if I do a INSERT
. I have a table of reservations with schedules, when someone makes a reservation I update the person field associated with the schedule, and that triggers the trigger
one that leaves the record of who registered, when, etc., but in turn I have an event that every day at 00 :00:00 update
all the people fields are empty so that the next day it can be solved again, that is the problem, the update
reserve one is ok, when the event is executed trigger
it takes the 24 empty updates and inserts 24 empty data in the audit table
This is the code trigger
I currently have
DELIMITER $$
CREATE TRIGGER Pc_Auditoria
AFTER UPDATE ON pcTotal
FOR EACH ROW
INSERT INTO auditoria (pc, personaAnterior, horario, persona, fecha_mod)
VALUES (NEW.pc, OLD.persona, NEW.horario, NEW.persona, NOW());
DELIMITER ;
When I make a reservation: The record inserted ok in the audit: How is the audit when the event is executed:
You can try the following:
Where
<tu condición aca>
it satisfies the validations that you think correspond. As you mention in your question if the field is empty then it should not be updated. I imagine that by empty you meanNULL
, so the condition would be something like this:According to your comments:
coordinador
.pcTotal
.With this in mind, your trigger would look like this:
Note the use of the function
COALESCE
to validate if the value ofNEW.coordinador
isNULL
then return an empty string''
.