zoukankan      html  css  js  c++  java
  • mysql 触发器的创建 修改 删除

    //做一个简单的练习,创建一个简单的触发器 完成添加文章的时候,自动加上时间,默认作者 为 ‘日记本的回忆‘

    show columns from test; //查看表结构

    //查看已存在触发器

    show  triggers  G

    //将结束符换成$

    d $

    //创建触发器, 用before 在插入的同时作用触发器(同时也作用于 update 更新) ,并应用到test表的每一行,时间unix时间戳

    create trigger insert_arc before insert on test
    for each row
    begin
        if new.nickname is null then
        set new.nickname='日记本的回忆';
        end if;
        if new.addtime is null then
            set new.addtime = unix_timestamp();
        end if;
    end
    $

    // 插入测试数据

    insert into test () values ()$

    //select * from test $

    //做一个简单的练习,创建一个简单的触发器 完成添加文章的时候,自动加上时间,默认作者 为 ‘日记本的回忆‘
    
     
    
    show columns from test; //查看表结构
    
     
    
    //查看已存在触发器
    
    show  triggers  G
    
    //将结束符换成$
    
    d $
    
    //创建触发器, 用before 在插入的同时作用触发器(同时也作用于 update 更新) ,并应用到test表的每一行,时间unix时间戳
    
    create trigger insert_arc before insert on test
    for each row
    begin
        if new.nickname is null then
        set new.nickname='日记本的回忆';
        end if;
        if new.addtime is null then
            set new.addtime = unix_timestamp();
        end if;
    end
    $
    
    // 插入测试数据
    
    insert into test () values ()$
    
    //select * from test $
    
     
    
    完成!!!
    
     
  • 相关阅读:
    HUSTOJ:Transit Tree Path
    HUSTOJ:5500 && 洛谷:P1412:经营与开发
    hdu:2036.改革春风吹满地
    hdu:2030.汉字统计
    Leetcode:338. Bit位计数
    【学习笔记】圆方树(CF487E Tourists)
    BZOJ3238 [Ahoi2013]差异
    CF 187D BRT Contract
    CF 36E Two Paths
    CF 49E Common ancestor
  • 原文地址:https://www.cnblogs.com/cocoliu/p/tianshupei88.html
Copyright © 2011-2022 走看看