我試圖創建一個Trigger
將通過一些IF ELSEIF
語句運行,並檢查新值是NULL
但是它只能到第一個IF
語句。MySQL更新設置值
This Trigger
is AFTER UPDATE
。我的問題是,如果我只有SET
一列值是什麼,其他SET
到,他們是NULL
或什麼。如果不是UPDATE
命令中的SET
,我如何測試此列。
示例更新:
UPDATE `stations_us`.`current_prices` SET `midPrice` = '3.59' WHERE `current_prices`.`_id` =1;
有沒有在這個時候更新,但可以基於PHP腳本更新等欄目。
觸發:
BEGIN
-- Definition start
IF(NEW.regPrice IS NOT NULL) THEN
INSERT INTO prices (stationID, price, type,
prevPrice, prevDate, dateCreated, apiKey, uid)
VALUES(NEW.stationID, NEW.regPrice, 'reg', OLD.regPrice,
OLD.regDate, NEW.regDate, NEW.lastApiUsed, NEW.lastUpdatedBy);
ELSEIF(NEW.midPrice IS NOT NULL) THEN
INSERT INTO prices (stationID, price, type,
prevPrice, prevDate, dateCreated, apiKey, uid)
VALUES(NEW.stationID, NEW.midPrice, 'mid', OLD.midPrice,
OLD.midDate, NEW.midDate, NEW.lastApiUsed, NEW.lastUpdatedBy);
ELSEIF(NEW.prePrice IS NOT NULL) THEN
INSERT INTO prices (stationID, price, type,
prevPrice, prevDate, dateCreated, apiKey, uid)
VALUES(NEW.stationID, NEW.prePrice, 'pre', OLD.prePrice,
OLD.preDate, NEW.preDate, NEW.lastApiUsed, NEW.lastUpdatedBy);
END IF;
-- Definition end
END
我不明白你的意思是什麼「如何測試這個列,如果它沒有設置這個更新命令。」你能解釋更多嗎? – octern 2012-08-01 16:34:36