zoukankan      html  css  js  c++  java
  • 触发器

    触发器:是用户定义在关系表上的一类由事件驱动的数据对象,也是一种保证数据完整性的方法.

    使用create trigger语句创建触发器

    格式:create trigger trigger_name trigger_time trigger_event

      on tb_table for each row trigger_body

    mysql-> create trigger mysql_test.cust_insert_trigger after insert

        -> on mysql_test.cust for each row set @str='one customer added!';

    mysql-> insert into mysql_test.cust

        -> values(null,'万华','F','长沙市','芙蓉区');

    mysql-> select @str;

    mysql-> drop trigger if exists mysql_test.cust_insert_trigger

    使用触发器 \同一个类型的触发器只能有一个,每个表最多有2x3个触发器

    三种触发器: insert触发器,delete触发器,update触发器

    insert触发器:在insert触发器代码内,可引用一个名为new(不区分大小写)的虚拟表,来访问被插入的行.

    在before insert触发器中,new中的值可以被更新.

    mysql-> create trigger mysql_test.cust_insert_trigger after insert

        -> on mysql_test.cust for each row set @str=new.cust_id;

    delete触发器: 在delete触发器代码内,可引用一个名为old(不区分大小写)的虚拟表,来访问被删除的行.

    old中的值全部是只读的,不能被更新.

    update触发器: 在update触发器代码内,可引用一个名为old(不区分大小写)的虚拟表,来访问update语句执行前的值,

    也可以引用一个名为new(不区分大小写)的虚拟表来访问更新后的值.

    mysql-> create trigger mysql_test.cust_update_trigger before update

        -> on mysql_test.cust for each row set new.cust_address=old.cust_contact;

  • 相关阅读:
    MyEclipse:详细使用教程
    JDK安装与配置详细图文教程
    windows下python3.6版本安装pygame
    windows下如何下载并安装Python
    python的 del 函数是删对象还是删引用
    python strip()函数的用法
    python的垃圾回收机制
    python中的sort方法
    python中del函数的垃圾回收
    两个数交换
  • 原文地址:https://www.cnblogs.com/lsxsx/p/13394210.html
Copyright © 2011-2022 走看看