zoukankan      html  css  js  c++  java
  • SQL 存储过程、触发器

    1、存储过程: 相当于函数,四要素:输入,输出,函数名,函数体

    创建存储过程

    create proc(这是存储过程的关键字) 存储过程名  |    ( create proc SelectAll

    参数 @a int, @b int                                        |

    as 函数体                                                       |     as select *from Student  

                                                                         |       select *from Score

                                                                         |      select *from Course

                                                                         |     select *from teacher

    return 值                                                       |

    调用:                                                           |

    exec 存储过程名                                               |               exec SelectAll)

    exec @a = 存储过程名

    2、触发器: 一个特殊的存储过程,没办法直接调用它,而是通过增删改的动作来触发它 (注意:一个表的一个动作只能有一个触发器

    create trigger(触发器关键字) 哪个表的哪个动作

    on 表名   --针对于哪一个表写的触发器

    for 动作  --针对于哪一个动作触发之后的触发器

    instead of 动作  --针对于哪一个动作执行替换(常用)

    as

     触发器内容

    例1、create trigger users_Insert
    on users
    for insert
    as
    select *from users

    例2、create trigger users-delete

    on users

    instead of delete

    as

    select *from users

  • 相关阅读:
    IDEA上传项目至git
    MyBatis 三种批量插入方式的对比 !
    华为 Java 编程军规 !
    Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    mysql数据库表的查询操作-总结
    idea返回git上历史版本
    JSONObject json对象-JSONArray json数组
    exception in thread "main" com.alibaba.fastjson.JSONException: exepct '[', but
    第三课
    第二课
  • 原文地址:https://www.cnblogs.com/zhulijun/p/6559738.html
Copyright © 2011-2022 走看看