zoukankan      html  css  js  c++  java
  • MySQL 触发器简单实例

    三个after 触发器

    DROP TABLE IF EXISTS tab1;
    CREATE TABLE tab1(
    tab1_id varchar(11),
    tab1_name varchar(11),
    tab1_pass varchar(11)
    );
    DROP TABLE IF EXISTS tab2;
    CREATE TABLE tab2(
    tab2_id varchar(11),
    tab2_name varchar(11),
    tab2_pass varchar(11)
    );
    -- 添加after insert触发器
    DROP TRIGGER IF EXISTS t_afterinsert_on_tab1;
    CREATE TRIGGER t_afterinsert_on_tab1
    AFTER INSERT ON tab1
    FOR EACH ROW
    BEGIN
    insert into tab2(tab2_id,tab2_name,tab2_pass) values(new.tab1_id,new.tab1_name,new.tab1_pass);
    END;
    INSERT INTO tab1(tab1_id,tab1_name,tab1_pass) values('0001','name1','pass1');
    SELECT * FROM tab1;
    SELECT * FROM tab2;

    -- 添加after update触发器
    DROP TRIGGER IF EXISTS t_afterupdate_on_tab1;
    CREATE TRIGGER t_afterupdate_on_tab1
    AFTER update ON tab1
    FOR EACH ROW
    BEGIN
    update tab2 set tab2_id = new.tab1_id, tab2_name = new.tab1_name, tab2_pass = new.tab1_pass;
    END;
    update tab1 set tab1_id = '0002', tab1_name = 'name2', tab1_pass = 'pass2';
    SELECT * FROM tab1;
    SELECT * FROM tab2;

    -- 添加after delete触发器
    DROP TRIGGER IF EXISTS t_afterdelete_on_tab1;
    CREATE TRIGGER t_afterdelete_on_tab1
    AFTER delete ON tab1
    FOR EACH ROW
    BEGIN
    delete from tab2 where tab2_id = old.tab1_id;
    END;
    delete from tab1 where tab1_id = '0002';
    SELECT * FROM tab1;
    SELECT * FROM tab2;

  • 相关阅读:
    《DSP using MATLAB》Problem 8.42
    《DSP using MATLAB》Problem 8.41
    《DSP using MATLAB》Problem 8.40
    《DSP using MATLAB》Problem 8.39
    IIR滤波器数字频带转换
    《DSP using MATLAB》Problem 8.38
    《DSP using MATLAB》Problem 8.37
    线性化①
    (七)根轨迹①
    (六)非零初始条件下的传递函数
  • 原文地址:https://www.cnblogs.com/silentmuh/p/5764193.html
Copyright © 2011-2022 走看看