原文: http://my.oschina.net/neochen/blog/294354

https://github.com/netkiller/mysql-zmq-plugin

有2张表:

表1:device, 里面有最主要的2个字段(id, device_type, .....),表明了"设备类型"与"ID";

表2:alarm_information,记录了每种设备的告警信息,其中有2个主要字段(id, device_type, ....);

要求:当 device中的某项被删除的时候,alarm_information中该设备所有的告警信息全部被删除。

在device中创建触发器:

///////////////////////////////////////////////////////////////////////////////////////////////

create   trigger   update_alarm_information   before delete   on   device   
  for   each   row

begin    
  set   @id=OLD.id; //保存被删除设备的“id”

set   @dtype=OLD.device_type;  //保存被删除记录的“device_type”
  delete   from   alarm_information   where   id=@id and device_type = @dtype;   
end;

///////////////////////////////////////////////////////////////////////////////////////////////

如果用Navicat for Mysql创建触发器就更加方便了

    1. 首先选择表device,点击右键,在弹出菜单中选择“设计表”
    2. 选择“触发器”
    3. 3.  在定义框中写入:
    4. begin    
        set   @id=OLD.id; //保存被删除设备的“id”

      set   @dtype=OLD.device_type;  //保存被删除记录的“device_type”
        delete   from   alarm_information   where   id=@id and device_type = @dtype;   
      end;

      4.  完成

    示例一
delimiter //
create trigger InsertUser
before insert on user
for each row
Begin
insert into user_group(uid,gid) values(new.uid,'group4444444444');
end;//
delimiter ; 示例二
delimiter //
create trigger InsertUser
before insert on user
for each row
Begin
IF new.Type=2 then
insert into user_group(uid,gid) values(new.uid,'group4444444444');
else
insert into user_group(uid,gid) values(new.uid,'group55555555555')
END IF;
end;//
delimiter ; 示例三:
delimiter //
create trigger InsertUser
before insert on user
for each row
Begin
IF new.type=1 then
insert into user_group(uid,gid) values(new.uid,'578d3369633b47bd9c1fe8bf905cbfb1');
END IF;
IF new.type=2 then
insert into user_group(uid,gid) values(new.uid,'387bcd57fc5a4c3c9de83ee210fef661');
END IF;
end;//
delimiter ;

php 小试 mysql-zmq-plugin 和 pthreads的更多相关文章

  1. 从源码角度看MySQL memcached plugin——0.大纲

    本系列文章介绍MySQL memcached plugin插件.剖析已经完成.先把链接弄好,内容会陆续补上. 大纲如下: 系统结构和引擎初始化(已完成) 线程模型和连接的状态机 containers表 ...

  2. 使用MySQL审计Plugin

    本文来源:http://blog.chinaunix.net/uid-20785090-id-5018977.html 越来越多的企业把应用往mysql上迁移,这时候对数据库的审计又成了一件紧急的事情 ...

  3. 远程连接MySQL错误“plugin caching_sha2_password could not be loaded”的解决办法

    远程连接MySQL错误"plugin caching_sha2_password could not be loaded"的解决办法 问题描述: 今天在阿里云租了一个服务器,当我用 ...

  4. mysql mybatis-generator plugin 有page实体类的分页

    page实体类 package cn.zsmy.tmp; import java.io.Serializable; /** * 分页对象. * */public final class Page im ...

  5. mysql mybatis-generator plugin 分页

    generator.xml配置如下: plugin必须紧跟context,否则会报错 <?xml version="1.0" encoding="UTF-8&quo ...

  6. Mysql错误处理: /usr/bin/mysqld_safe: line xxx: xxxx Killed ... (mysql自动停止 Plugin FEDERATED is disabled 的完美解决方法)

    哈哈哈,问题总算解决,内心抑不住的开心 centos mysql 问题:Plugin 'FEDERATED' is disabled. /usr/sbin/mysqld: Table 'mysql.p ...

  7. 连接MySQL错误“plugin caching_sha2_password could not be loaded”的解决办法

    MySQL新版默认使用caching_sha2_password作为身份验证插件,而旧版是使用mysql_native_password.当连接MySQL时报错“plugin caching_sha2 ...

  8. 从源码角度看MySQL memcached plugin——1. 系统结构和引擎初始化

    本章尝试回答两个问题: 一.memcached plugin与MySQL的关系: 二.MySQL系统如何启动memcached plugin. 1. memcached plugin与MySQL的关系 ...

  9. MySQL Authentication plugin 'caching_sha2_password' cannot be loaded

    很多用户在使用Navicat Premium 12连接MySQL数据库时会出现Authentication plugin 'caching_sha2_password' cannot be loade ...

  10. mysql Authentication plugin 'caching_sha2_password' is not supported问题处理

    使用mysql8.0版本,登录失败,提示 Authentication plugin 'caching_sha2_password' is not supported. 原因是在MySQL 8.0以后 ...

随机推荐

  1. 2016"百度之星" - 初赛(Astar Round2A)All X(数学 矩阵)

    All X  Accepts: 1281  Submissions: 7580  Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: 65536 ...

  2. Implementing Navigation with UINavigationController

    Implementing Navigation with UINavigationController Problem You would like to allow your users to mo ...

  3. 限制非安全IP访问

    这个是一个检测ip是否非法的php函数,适应于白名单,黑名单功能开发,主要场景应用于:api来源限制,访问限制等. /** * 安全IP检测,支持IP段检测 * @param string $ip 要 ...

  4. hdu 4046 2011北京赛区网络赛G 线段树 ***

    还带这么做的,卧槽,15分钟就被A了的题,居然没搞出来 若某位是1,则前两个为wb,这位就是w #include<cstdio> #include<cstring> #defi ...

  5. linux 用户之间的切换

    从root用户切换到普通用户fxm, 使用如下命令:su - fxm 从普通用户切换到root用户,使用如下命令:su - 或者 su, root可以省略不写.

  6. HTML Entity Sets - All

    http://www.htmlentities.com/html/entities/ The view below displays the characters used in the offici ...

  7. Hibernate的核心API

    Configuration:负责管理Hibernate的配置信息 1.加载核心配置文件 核心配置有两种: hibernate.properties 加载:Configuration configura ...

  8. 【微信Java开发 --番外篇】错误解析

    虽然在微信开发过程中,会有微信公众平台开发者文档中的<全局返回码>作为错误的参考对比:但是依旧的,会觉得有时候的问题莫名其妙.[注:本人使用weixin-java-tools进行开发] 下 ...

  9. 深入理解KMP算法

    前言:本人最近在看<大话数据结构>字符串模式匹配算法的内容,但是看得很迷糊,这本书中这块的内容感觉基本是严蔚敏<数据结构>的一个翻版,此书中给出的代码实现确实非常精炼,但是个人 ...

  10. C#多线程编程总结

    VS2008.C#3.0在WinForm开发中,我们通常不希望当窗体上点了某个按钮执行某个业务的时候,窗体就被卡死了,直到该业务执行完毕后才缓过来.一个最直接的方法便是使用多线程.多线程编程的方式在W ...