更新后的SQL触发器无法正常工作

时间:2014-11-07 22:15:53

标签: mysql sql triggers

请帮帮我......

USE `arma3life`;
DELIMITER $$
CREATE DEFINER=`zoxxen`@`localhost` TRIGGER `money_log` AFTER UPDATE ON `players` FOR EACH ROW
BEGIN
    IF NEW.`bankacc` <> OLD.`bankacc` OR NEW.`cash` <> OLD.`cash` THEN
        INSERT INTO `supportertool_money` (
            `i_player_id`
            ,`i_bankacc`
            ,`i_cash`
            ,`dt_inserted`
        )
        VALUES (
            NEW.`playerid`
            ,NEW.`bankacc`
            ,NEW.`cash`
            ,NOW()
        );
    END IF;
END $$
DELIMITER ;

必须有一个问题..我不能再更新我的行了,而且Trigger无效 我使用的是innodb

1 个答案:

答案 0 :(得分:0)

您的if声明是:

IF NEW.`bankacc` <> OLD.`bankacc` OR NEW.`cash` <> OLD.`cash` THEN

当值为NULL时,条件不符合您的预期。试试这个:

IF NEW.bankacc <> OLD.bankacc OR
   NEW.bankacc is null and OLD.bankacc is not null or
   NEW.bankacc is not null and OLD.bankacc is null or
   NEW.cash <> OLD.`cash` or
   NEW.cash is null and OLD.cash is not null or
   NEW.cash is not null and OLD.cash is null then