I think I read that the delete trigger doesn’t know what data was deleted and loops over the whole table applying the trigger. Is that true?
Does that mean that the before delete loops over the whole table before the data is deleted and after delete loops over the whole table after the delete occurs?
Is there no way to loop over just the deleted records? So If 10 records are deleted loop over them?
DELIMITER $$
DROP TRIGGER `before_delete_jecki_triggername`$$
CREATE TRIGGER before_delete_triggername
BEFORE DELETE ON table
FOR EACH ROW
BEGIN
/*do stuff*/
END$$
DELIMITER ;
Thanks,
Mat
I think it was due to a confusion with
FOR EACH ROWstatement.It is only for “matched records for the statement issued before trigger is invoked.”
If there exists
Nnumber of records in a table and matches records forwhere id=x,assuming
xcauses a result of less thanNrecords, sayN-5, thenFOR EACH ROWcauses a loop forN-5times only.UPDATE:
A sample test run on the rows affected due to
FOR EACH ROWstatement is shown below.