触发器创建及Navicat中使用
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 isAFTER
.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 forDELETE
andUPDATE
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 simpleSET
that accumulates into a user variable the values inserted into theamount
column. The statement refers to the column asNEW.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
最新文章
- 用js效果做的简单焦点图
- IOS 如何隐藏tabbar
- 20135328信息安全系统设计基础第一周学习总结(Linux应用)
- JQuery学习(1)
- jQuery请求后台接口
- Windows Server 2016-安装AD域服务注意事项
- Spring注解简介
- JavaEE 藏经阁
- centos7启动过程及systemd详细说明
- s6-2 UDP
- python 内建函数专题
- How Not to Crash系列地址
- new DialogInterface.OnClickListener()报错的解决办法
- 搭建好看的静态博客(使用Hexo进行搭建)
- Git 学习(七)标签管理
- binutils工具集之---addr2line
- 001-mybatis框架
- plan,idea,and dream
- Jenkins+Ant+Jmeter接口自动化集成测试实例
- 使用maven拆分项目
热门文章
- 将Nagios监控信息存入Mysql
- C#中的托管和非托管
- bootstrap/moban191/js/templatemo_custom.js
- Oracle存储过程单步调试方法
- jquery ui 常用(一)(自动完成 | 标签页 | 折叠面板 | 带图标的按钮 | 日期选择器| )
- poj1961 Period
- Digital Roots 分类: HDU 2015-06-19 22:56 13人阅读 评论(0) 收藏
- 【算法题目】包含min函数的栈
- hiho(1081),SPFA最短路,(非主流写法)
- 使用UML进行项目开发