• T-SQL---触发器


    create trigger trig_transInfo
    on transInfo
    for insert
    as 
    declare @type char(4),@outMoney Money
    declare @myCardID char(10),@balanceMoney
    select @type=transType,@outMoney=transMoney,@myCardID=cardID
    from inserted --从inserted表获取交易类型、教员金额等
    if (@type='支取') --根据交易类型,减少或增加对应卡号的余额
     update bank set currentMoney=currentMoney-@outMoney where cardID=myCardID
    else 
      update bank set currentMoney=currentMoney+@outMoney where cardID=myCardID
    ...

     触发器触发时:

    (1)系统自动在内存中创建deleted表和inserted表

    (2)只读,不允许修改;触发器执行完成后,自动删除

    inserted表

    (1)临时保存了插入或更新后的记录行

    (2)可以从inserted表中检查插入的数据是否满足业务需求

    (3)如果不满足,则向用户报告错误消息,并回滚插入操作

    deleted表

    (1)临时保存了删除或更新前的记录行

    (2)可以从deleted表检查被删除的数据是否满足业务需求

    (3)如果不满足,则向用户报告错误消息,并回滚删除操作

  • 相关阅读:
    C#之事件
    C#之委托
    CIC许可更新
    HMP许可更新
    知识库上传
    [转]spring中<tx:advice></tx:advice>意义
    [转]spring property标签中的 ref属性和ref 标签有什么不同
    [转] Spring@Autowired注解与自动装配
    [转]SpringMVC入门
    [转]SpringMVC拦截器详解[附带源码分析]
  • 原文地址:https://www.cnblogs.com/beast-king/p/4523316.html
Copyright © 2020-2023  润新知