mysql - 更新后 SQL 触发器不起作用

标签 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 ;

一定有问题..我无法再更新我的行并且触发器无法工作 我正在使用 innodb

最佳答案

您的 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

关于mysql - 更新后 SQL 触发器不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26811004/

相关文章:

php - 制作 'wish list' 功能的最佳方法

mysql - 在触发器中创建 View

Mysql 'statement level' 触发器...你可以用两个技巧来做到这一点

php - Laravel 4 Eloquent 返回错误的 ID

postgresql - 如何在postgresql中创建一个时间驱动的触发器

php-mysql - 需要匹配两个互补的关键字,而不是独立的关键字

php - Laravel 迁移无法在新数据库上运行

php - 如何保护本地托管网站的源代码?

python - 如何从sql查询中提取表名和列名?

sql - 架构更改脚本 : Validation and test cases