The goal of this trigger is to insert old data per row into a table if the updated data per row does not equal the current data per row.
delimiter //
CREATE TRIGGER history BEFORE UPDATE ON table1
FOR EACH ROW
BEGIN
IF NEW.salePrice <> OLD.salePrice THEN
INSERT INTO history_price (modelNumber,salePrice)
VALUES ('modelNumber','OLD.salePrice');
ELSEIF NEW.salePrice = OLD.salePrice THEN
SET NEW.salePrice = OLD.salePrice;
END IF;
END;//
delimiter ;
All in all, this concept should be working, but the insert is not working. It is only inserting the actual text, not the values.
More specifically:
INSERT INTO history_price (modelNumber,salePrice)
VALUES
('modelNumber','OLD.salePrice');
This part of my trigger literally inserts modelNumber, and OLD.salePrice into my history table if the updated values are not equal.
What is wrong with this query?