I need to create a Trigger that checks BEFORE INSERT
. For each row, if pc.price <= 0 then the price should be set to its absolute value
CREATE TRIGGER Neg_PC_Price
BEFORE INSERT ON PC
FOR EACH ROW
BEGIN
IF NEW.price <= 0
THEN ABS(NEW.price)
END IF;
END;
This is what I pieced together from a different solution but instead of setting the new price they returned an error statement and not sure how to input with the updated positive price.
CodePudding user response:
I do not see the reason in additional and obviously excess IF statement. Simply
CREATE TRIGGER Neg_PC_Price
BEFORE INSERT ON PC
FOR EACH ROW
SET NEW.price = ABS(NEW.price);