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

触发器创建及Navicat中使用的更多相关文章

  1. Oracle 触发器在日志管理开发中的应用

    摘要: 本文讨论了利用数据库中的触发器对日志管理进行设计与实现的方法, 是对原来在客户端软件中编写日志管理方法的一种改进, 并给出了 Oracle9i 中的实例演示.关键词: Oracle; 触发器; ...

  2. 【Mysql】mysql使用触发器创建hash索引

    概述 若设计的数据表中,包含较长的字段,比如URL(通常都会比较长),查询时需要根据该字段进行过滤: select * from table_xxx where url = 'xxxxxxx'; 为了 ...

  3. java连接Oracle数据库实现增删改查并在Navicat中显示

    创建TEST表 eclipse中的java项目 代码 数据库方法类 DBUtil: package util; import java.sql.Connection; import java.sql. ...

  4. 在Navicat中如何新建数据库和表并做查询

    上一篇文章,小编给大家分享了在Navicat中如何远程连接数据库,没有来得及上车的小伙伴可以戳这篇文章:在Ubuntu14.04中配置mysql远程连接教程.今天小编给大家分享一下如何在Navicat ...

  5. Eclipse在已创建的project中导入其他文件

    Eclipse在已创建的project中导入其他文件 前两天被同事问到,如何通过不拷贝源文件的方式,在之前已经创建好的project中直接导入其他目录下的文件, 整理了一下,将目前所知道的eclips ...

  6. 使用eclipse创建在myeclipse中运行的web工程

    今天在跟随慕课网学习java时,遇到课程中老师使用Myeclipse,我用的是eclipse,那么就使用eclipse创建在Myeclipse项目 参考: 如何在Eclipse配置Tomcat服务器 ...

  7. 在Navicat 中给Mysql中的某字段添加前缀00

    第一次分享心得,希望大家多多关注. 我遇到的情况是这样的,在Navicat中某表的varchar字段内容长度不够5的在内容前面添加‘0’:如字段内容是 101 我就要改成00101: 其中有2个难点: ...

  8. 创建类似于Oracle中decode的函数

    -- 创建类似于Oracle中decode的函数create or replace function decode(variadic p_decode_list text[])returns text ...

  9. 1.django项目的创建(在CMD中)

    django项目的创建(在CMD中) 1.切换到你想要存储项目的位置,我这里保存在桌面上 cd Desktop 2.创建一个django项目,项目名叫guest django-admin startp ...

随机推荐

  1. hibernate核心接口,和扩展接口。回顾笔记,以前没记,现在补上,纯手工敲的。

    hibernate核心接口: 所有的hibernate应用都会访问hibernate的5个核心接口 1,Configuration接口 Configuration用于配置并且根启动Hibernate. ...

  2. hdwiki 数据库结构说明

    HDWiki数据库结构说明          以下标有“A”的表示该列为自增列,标有“P”的表示该列为主码,标有“I”的表示该列为索引列,标有“U”的表示该列为唯一列,标有“F”的表示全文搜索.   ...

  3. (jdbc)取得数据库自动生成的主键方法

    一些类,在前面的博客中有,就不重复了 public class Test2 { TestDAO t=new TestDAO(); /*前提是数据表的主键是自动增加的, *取得数据库自动生成的主键 * ...

  4. asp.net 页面跳转传值的几种方式

    参考地址: http://blog.csdn.net/zzzzzzzert/article/details/8486143 protected void Button1_Click(object se ...

  5. 如何用Pr完成作业~

    要求~ 我的工具~(随便搞搞就好了,自己的录音还没弄~)

  6. C# 对Xml的常用操作

    using System.Xml;  //初始化一个xml实例   XmlDocument xml=new XmlDocument(); //导入指定xml文件  xml.Load(path);   ...

  7. 2016年11月1日 星期二 --出埃及记 Exodus 19:17

    2016年11月1日 星期二 --出埃及记 Exodus 19:17 Then Moses led the people out of the camp to meet with God, and t ...

  8. java-cmd-命令行编译和运行java文件

    一.使用的工具 1.javac 2.java 二.命令 项目目录只这样的 D:/project/src/com/example/Child.java D:/project/src/com/exampl ...

  9. PHP 之 FastCGI 与 mod_php 详解

    背景 PHP最常用的方式是以模块的方式(mod_php)运行在Apache中,也是Apache运行PHP的默认方式:但在Nginx中,Nginx又使用的是PHP-FPM,但是PHP-FPM到底是个什么 ...

  10. Objective-C学习笔记_Xcode模拟命令行填入参数执行

    菜单Product->Edit Scheme 左边找到run xxx,点击后再邮编选择Arguments面板中就可以设置Xcode在运行命令行app时模拟输入参数. 设置完成后再次run就会自动 ...