开发者

MySQL Trigger-- Not inserting correct values

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;

    EN开发者_JAVA技巧D 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?


modelNumber and OLD.salePrice probably should not be in single quotes.


Try then changing it to

insert into history_price (old.ModelNumber,old.salePrice)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜