I am new to database trigger. I really have no idea why i cant update the Label if the Quantity more than equal to 1000
CREATE TRIGGER TRG_UPDATE_STATUS
AFTER UPDATE ON product
FOR EACH ROW
BEGIN
IF NEW.QuantitySold >= 1000 THEN
SET NEW.Label = 'BestSeller'
END IF
END
Here is the trigger I have.
Best Answer
You can only make persistent changes to
NEW
in abefore row
trigger. Anafter
trigger doesn't fire until the record has already been written to the table.To change the data that will be written to the table, you must use a
before row
trigger. ChangingNEW
in anafter row
trigger is possible, but pointless, since the contents ofNEW
get written to the table before anafter
trigger executes, as is explained in the documentation.