I need a statement that allows to change some fields in table1 when table2 was updated.
I have currently the following code:
delimiter //
CREATE TRIGGER check BEFORE UPDATE ON table2
FOR EACH ROW
BEGIN
IF NEW.Count <> OLD.Count THEN
...
END IF;
END//
delimiter ;
However, table1 is very large and there are a lot of update events, so I’m afraid that this code can slowdown my server. So I want to know if there is some solution that will not look over all records in it, but only those updated?
The trigger will not “look” over all records. Because you declared the trigger as
FOR EACH ROWonly a single row will be dealt with in the trigger.As the trigger is execute for each row,
NEWandOLDreference a single row as, which means that the conditionNEW.Count <> OLD.Countsimply compares two (simple) column values