• 触发器写法


    CREATE TABLE IF NOT EXISTS `wp_postmeta_log` (
      `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
      `table_name` varchar(15) DEFAULT NULL,
      `action` varchar(15) DEFAULT NULL,
      `meta_id` bigint(20) unsigned NOT NULL,
      `post_id` bigint(20) unsigned NOT NULL DEFAULT '0',
      `meta_key` varchar(255) DEFAULT NULL,
      `meta_value` longtext,
      `startDate` datetime DEFAULT NULL,
      `endDate` datetime DEFAULT NULL,
      PRIMARY KEY (`id`),
      KEY `post_id` (`post_id`),
      KEY `meta_key` (`meta_key`)
    ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=14894 ;
    
    DELIMITER //
    /* Trigger for INSERT */
    CREATE TRIGGER WpPostMetaInsert AFTER INSERT ON wp_postmeta FOR EACH ROW BEGIN
       DECLARE N DATETIME;
       SET N = now();
     
       INSERT INTO wp_postmeta_log (table_name, action, meta_id, post_id, meta_key, meta_value, StartDate, EndDate)
       VALUES ('wp_postmeta', 'INSERT', NEW.meta_id, NEW.post_id, NEW.meta_key, NEW.meta_value, N, NULL);
    END //
    
    /* Trigger for DELETE */
    CREATE TRIGGER WpPostMetaDelete AFTER DELETE ON wp_postmeta FOR EACH ROW BEGIN
       DECLARE N DATETIME;
       SET N = now();
    
       UPDATE wp_postmeta_log
          SET EndDate = N
        WHERE meta_id = OLD.meta_id
          AND EndDate IS NULL;
    
       INSERT INTO wp_postmeta_log (table_name, action, meta_id, post_id, meta_key, meta_value, StartDate, EndDate)
       VALUES ('wp_postmeta', 'DELETE', OLD.meta_id, OLD.post_id, OLD.meta_key, OLD.meta_value, N, NULL);
    END //
    
    /* Trigger for UPDATE */
    CREATE TRIGGER WpPostMetaUpdate AFTER UPDATE ON wp_postmeta FOR EACH ROW BEGIN
       DECLARE N DATETIME;
       SET N = now();
    
       UPDATE wp_postmeta_log
          SET EndDate = N
        WHERE meta_id = OLD.meta_id
          AND EndDate IS NULL;
     
       INSERT INTO wp_postmeta_log (table_name, action, meta_id, post_id, meta_key, meta_value, StartDate, EndDate)
       VALUES ('wp_postmeta', 'UPDATE', NEW.meta_id, NEW.post_id, NEW.meta_key, NEW.meta_value, N, NULL);
    END //
    
    /* --- */
    
    /* Trigger for INSERT */
    CREATE TRIGGER WpPostMetaInsert2 AFTER INSERT ON wp_2_postmeta FOR EACH ROW BEGIN
       DECLARE N DATETIME;
       SET N = now();
     
       INSERT INTO wp_postmeta_log (table_name, action, meta_id, post_id, meta_key, meta_value, StartDate, EndDate)
       VALUES ('wp_2_postmeta', 'INSERT', NEW.meta_id, NEW.post_id, NEW.meta_key, NEW.meta_value, N, NULL);
    END //
    
    /* Trigger for DELETE */
    CREATE TRIGGER WpPostMetaDelete2 AFTER DELETE ON wp_2_postmeta FOR EACH ROW BEGIN
       DECLARE N DATETIME;
       SET N = now();
    
       UPDATE wp_postmeta_log
          SET EndDate = N
        WHERE meta_id = OLD.meta_id
          AND EndDate IS NULL;
    
       INSERT INTO wp_postmeta_log (table_name, action, meta_id, post_id, meta_key, meta_value, StartDate, EndDate)
       VALUES ('wp_2_postmeta', 'DELETE', OLD.meta_id, OLD.post_id, OLD.meta_key, OLD.meta_value, N, NULL);
    END //
    
    /* Trigger for UPDATE */
    CREATE TRIGGER WpPostMetaUpdate2 AFTER UPDATE ON wp_2_postmeta FOR EACH ROW BEGIN
       DECLARE N DATETIME;
       SET N = now();
    
       UPDATE wp_postmeta_log
          SET EndDate = N
        WHERE meta_id = OLD.meta_id
          AND EndDate IS NULL;
     
       INSERT INTO wp_postmeta_log (table_name, action, meta_id, post_id, meta_key, meta_value, StartDate, EndDate)
       VALUES ('wp_2_postmeta', 'UPDATE', NEW.meta_id, NEW.post_id, NEW.meta_key, NEW.meta_value, N, NULL);
    END //
    
    /* --- */
    
    /* Trigger for INSERT */
    CREATE TRIGGER WpPostMetaInsert3 AFTER INSERT ON wp_3_postmeta FOR EACH ROW BEGIN
       DECLARE N DATETIME;
       SET N = now();
     
       INSERT INTO wp_postmeta_log (table_name, action, meta_id, post_id, meta_key, meta_value, StartDate, EndDate)
       VALUES ('wp_3_postmeta', 'INSERT', NEW.meta_id, NEW.post_id, NEW.meta_key, NEW.meta_value, N, NULL);
    END //
    
    /* Trigger for DELETE */
    CREATE TRIGGER WpPostMetaDelete3 AFTER DELETE ON wp_3_postmeta FOR EACH ROW BEGIN
       DECLARE N DATETIME;
       SET N = now();
    
       UPDATE wp_postmeta_log
          SET EndDate = N
        WHERE meta_id = OLD.meta_id
          AND EndDate IS NULL;
    
       INSERT INTO wp_postmeta_log (table_name, action, meta_id, post_id, meta_key, meta_value, StartDate, EndDate)
       VALUES ('wp_3_postmeta', 'DELETE', OLD.meta_id, OLD.post_id, OLD.meta_key, OLD.meta_value, N, NULL);
    END //
    
    /* Trigger for UPDATE */
    CREATE TRIGGER WpPostMetaUpdate3 AFTER UPDATE ON wp_3_postmeta FOR EACH ROW BEGIN
       DECLARE N DATETIME;
       SET N = now();
    
       UPDATE wp_postmeta_log
          SET EndDate = N
        WHERE meta_id = OLD.meta_id
          AND EndDate IS NULL;
     
       INSERT INTO wp_postmeta_log (table_name, action, meta_id, post_id, meta_key, meta_value, StartDate, EndDate)
       VALUES ('wp_3_postmeta', 'UPDATE', NEW.meta_id, NEW.post_id, NEW.meta_key, NEW.meta_value, N, NULL);
    END //
    
    /* --- */
    
    /* Trigger for INSERT */
    CREATE TRIGGER WpPostMetaInsert4 AFTER INSERT ON wp_4_postmeta FOR EACH ROW BEGIN
       DECLARE N DATETIME;
       SET N = now();
     
       INSERT INTO wp_postmeta_log (table_name, action, meta_id, post_id, meta_key, meta_value, StartDate, EndDate)
       VALUES ('wp_4_postmeta', 'INSERT', NEW.meta_id, NEW.post_id, NEW.meta_key, NEW.meta_value, N, NULL);
    END //
    
    /* Trigger for DELETE */
    CREATE TRIGGER WpPostMetaDelete4 AFTER DELETE ON wp_4_postmeta FOR EACH ROW BEGIN
       DECLARE N DATETIME;
       SET N = now();
    
       UPDATE wp_postmeta_log
          SET EndDate = N
        WHERE meta_id = OLD.meta_id
          AND EndDate IS NULL;
    
       INSERT INTO wp_postmeta_log (table_name, action, meta_id, post_id, meta_key, meta_value, StartDate, EndDate)
       VALUES ('wp_4_postmeta', 'DELETE', OLD.meta_id, OLD.post_id, OLD.meta_key, OLD.meta_value, N, NULL);
    END //
    
    /* Trigger for UPDATE */
    CREATE TRIGGER WpPostMetaUpdate4 AFTER UPDATE ON wp_4_postmeta FOR EACH ROW BEGIN
       DECLARE N DATETIME;
       SET N = now();
    
       UPDATE wp_postmeta_log
          SET EndDate = N
        WHERE meta_id = OLD.meta_id
          AND EndDate IS NULL;
     
       INSERT INTO wp_postmeta_log (table_name, action, meta_id, post_id, meta_key, meta_value, StartDate, EndDate)
       VALUES ('wp_4_postmeta', 'UPDATE', NEW.meta_id, NEW.post_id, NEW.meta_key, NEW.meta_value, N, NULL);
    END //
    
    /* --- */
    
    /* Trigger for INSERT */
    CREATE TRIGGER WpPostMetaInsert5 AFTER INSERT ON wp_5_postmeta FOR EACH ROW BEGIN
       DECLARE N DATETIME;
       SET N = now();
     
       INSERT INTO wp_postmeta_log (table_name, action, meta_id, post_id, meta_key, meta_value, StartDate, EndDate)
       VALUES ('wp_5_postmeta', 'INSERT', NEW.meta_id, NEW.post_id, NEW.meta_key, NEW.meta_value, N, NULL);
    END //
    
    /* Trigger for DELETE */
    CREATE TRIGGER WpPostMetaDelete5 AFTER DELETE ON wp_5_postmeta FOR EACH ROW BEGIN
       DECLARE N DATETIME;
       SET N = now();
    
       UPDATE wp_postmeta_log
          SET EndDate = N
        WHERE meta_id = OLD.meta_id
          AND EndDate IS NULL;
    
       INSERT INTO wp_postmeta_log (table_name, action, meta_id, post_id, meta_key, meta_value, StartDate, EndDate)
       VALUES ('wp_5_postmeta', 'DELETE', OLD.meta_id, OLD.post_id, OLD.meta_key, OLD.meta_value, N, NULL);
    END //
    
    /* Trigger for UPDATE */
    CREATE TRIGGER WpPostMetaUpdate5 AFTER UPDATE ON wp_5_postmeta FOR EACH ROW BEGIN
       DECLARE N DATETIME;
       SET N = now();
    
       UPDATE wp_postmeta_log
          SET EndDate = N
        WHERE meta_id = OLD.meta_id
          AND EndDate IS NULL;
     
       INSERT INTO wp_postmeta_log (table_name, action, meta_id, post_id, meta_key, meta_value, StartDate, EndDate)
       VALUES ('wp_5_postmeta', 'UPDATE', NEW.meta_id, NEW.post_id, NEW.meta_key, NEW.meta_value, N, NULL);
    END //
    
    /* --- */
    
    /* Trigger for INSERT */
    CREATE TRIGGER WpPostMetaInsert6 AFTER INSERT ON wp_6_postmeta FOR EACH ROW BEGIN
       DECLARE N DATETIME;
       SET N = now();
     
       INSERT INTO wp_postmeta_log (table_name, action, meta_id, post_id, meta_key, meta_value, StartDate, EndDate)
       VALUES ('wp_6_postmeta', 'INSERT', NEW.meta_id, NEW.post_id, NEW.meta_key, NEW.meta_value, N, NULL);
    END //
    
    /* Trigger for DELETE */
    CREATE TRIGGER WpPostMetaDelete6 AFTER DELETE ON wp_6_postmeta FOR EACH ROW BEGIN
       DECLARE N DATETIME;
       SET N = now();
    
       UPDATE wp_postmeta_log
          SET EndDate = N
        WHERE meta_id = OLD.meta_id
          AND EndDate IS NULL;
    
       INSERT INTO wp_postmeta_log (table_name, action, meta_id, post_id, meta_key, meta_value, StartDate, EndDate)
       VALUES ('wp_6_postmeta', 'DELETE', OLD.meta_id, OLD.post_id, OLD.meta_key, OLD.meta_value, N, NULL);
    END //
    
    /* Trigger for UPDATE */
    CREATE TRIGGER WpPostMetaUpdate6 AFTER UPDATE ON wp_6_postmeta FOR EACH ROW BEGIN
       DECLARE N DATETIME;
       SET N = now();
    
       UPDATE wp_postmeta_log
          SET EndDate = N
        WHERE meta_id = OLD.meta_id
          AND EndDate IS NULL;
     
       INSERT INTO wp_postmeta_log (table_name, action, meta_id, post_id, meta_key, meta_value, StartDate, EndDate)
       VALUES ('wp_6_postmeta', 'UPDATE', NEW.meta_id, NEW.post_id, NEW.meta_key, NEW.meta_value, N, NULL);
    END //
    

      

  • 相关阅读:
    django实现github第三方本地登录
    django扩展User模型(model),profile
    WSGI
    Linux查看配置文件中未被注释的有效配置行
    virsh 命令
    qemu-img命令
    python logging
    oslo.messaging
    集成kafka的身份认证(SASL/PLAIN)到kubernets环境中
    Helm基础知识
  • 原文地址:https://www.cnblogs.com/freespider/p/11207260.html
Copyright © 2020-2023  润新知