mysql中的触发器(trigger)使用

 Trigger:

  示例:

mysql> CREATE TABLE account (acct_num INT, amount DECIMAL(10,2));
Query OK, 0 rows affected (0.03 sec) mysql> CREATE TRIGGER ins_sum BEFORE INSERT ON account
-> FOR EACH ROW SET @sum = @sum + NEW.amount;
Query OK, 0 rows affected (0.06 sec)

  

  解析:<原谅我这懒惰的搬运工>

   

   The CREATE TRIGGER statement creates a trigger named ins_sum that is associated with the account table. It also includes clauses that specify the trigger action time, the triggering event, and what to do when the trigger activates:

  • The keyword BEFORE indicates the trigger action time. In this case, the trigger activates before each row inserted into the table. The other permitted keyword here is AFTER.

  • The keyword INSERT indicates the trigger event; that is, the type of operation that activates the trigger. In the example, INSERT operations cause trigger activation. You can also create triggers for DELETE and UPDATE operations.

  • The statement following FOR EACH ROW defines the trigger body; that is, the statement to execute each time the trigger activates, which occurs once for each row affected by the triggering event. In the example, the trigger body is a simple SET that accumulates into a user variable the values inserted into the amount column. The statement refers to the column as NEW.amount which means “the value of theamount column to be inserted into the new row.”

  具体参见:http://dev.mysql.com/doc/refman/5.7/en/trigger-syntax.html

  Navicat中使用

  1.选中要添加触发器的表;

    2.打开其设计表;

    3.打开触发器,在指定栏中设置触发器;

   

   具体参见:http://blog.csdn.net/cqnuztq/article/details/9735245

最新文章

  1. 用js效果做的简单焦点图
  2. IOS 如何隐藏tabbar
  3. 20135328信息安全系统设计基础第一周学习总结(Linux应用)
  4. JQuery学习(1)
  5. jQuery请求后台接口
  6. Windows Server 2016-安装AD域服务注意事项
  7. Spring注解简介
  8. JavaEE 藏经阁
  9. centos7启动过程及systemd详细说明
  10. s6-2 UDP
  11. python 内建函数专题
  12. How Not to Crash系列地址
  13. new DialogInterface.OnClickListener()报错的解决办法
  14. 搭建好看的静态博客(使用Hexo进行搭建)
  15. Git 学习(七)标签管理
  16. binutils工具集之---addr2line
  17. 001-mybatis框架
  18. plan,idea,and dream
  19. Jenkins+Ant+Jmeter接口自动化集成测试实例
  20. 使用maven拆分项目

热门文章

  1. 将Nagios监控信息存入Mysql
  2. C#中的托管和非托管
  3. bootstrap/moban191/js/templatemo_custom.js
  4. Oracle存储过程单步调试方法
  5. jquery ui 常用(一)(自动完成 | 标签页 | 折叠面板 | 带图标的按钮 | 日期选择器| )
  6. poj1961 Period
  7. Digital Roots 分类: HDU 2015-06-19 22:56 13人阅读 评论(0) 收藏
  8. 【算法题目】包含min函数的栈
  9. hiho(1081),SPFA最短路,(非主流写法)
  10. 使用UML进行项目开发