dpbtbcz6650 2016-05-05 10:54
浏览 17

mysql触发更新操作问题

hi all am a beginner in php

Am working on trigger i need to insert the changed values in trigger table when the tables get updated,while inserting in trigger i need the column name of the changed fields so i have tried the following code but it not working only it accepts one condition on trigger its not possible to set multiple triggers for a single table help me to solve this issues

IF NEW.account_holder <> OLD.account_holder THEN  

    INSERT INTO bank_trigger (filed_name) VALUES('account');

END IF

IF NEW.branch_name <> OLD.branch_name THEN  

    INSERT INTO bank_trigger (filed_name) VALUES('branch_name');

END IF;
  • 写回答

2条回答 默认 最新

  • dongmao9217 2016-05-05 11:23
    关注

    Before I used this

    DROP TRIGGER IF EXISTS some_trigger;

    DELIMITER $$
    
    CREATE TRIGGER `some_trigger` AFTER UPDATE ON `table_1` FOR EACH ROW 
        BEGIN
    
            IF !(OLD.a <=> NEW.a AND OLD.b <=> NEW.b) THEN
                INSERT INTO `table_2` (
                    `a`,
                     `b`
                ) VALUES (
                    NEW.`a`,
                    NEW.`b`
                );
            END IF;
        END;$$
    
    DELIMITER ;
    
    评论

报告相同问题?

悬赏问题

  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教