我正在尝试创建一个Trigger
将通过一些IF ELSEIF
语句运行并检查新值NULL
但是它只适用于第一个IF
语句。
这Trigger
是AFTER UPDATE
. 我的问题是,如果我只是SET
一个列值,其他列是什么SET
,是它们NULL
还是什么。SET
如果此列不在此UPDATE
命令上,我该如何测试它。
示例更新:
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