MSSQL数据库触发器--更新(update),删除(delete),插入(insert)

创建studentcourse(学号,姓名,课程1,课程2...)        information(学号,姓名,性别,籍贯,联系电话....) 两张表

更新型触发器(update):

Create Trigger T1
            On studentcourse                              --在Studentcourese表中创建触发器
            for Update                               --为什么事件触发
          As                                             --事件触发后所要做的事情
            if Update(姓名)           
            begin

              Update information
                Set 姓名=i.姓名
                From information inf, Deleted        d ,Inserted i           --Deleted和Inserted临时表
                Where inf.学号=d.学号

            end

删除型触发器(delete):

Create trigger T2
            On Studentcourse
            for Delete
          As
            Delete information
              From information inf, Deleted d
              Where inf.学号=d.学号

插入型触发器(insert):

Create trigger T3
            On Studentcourse
            for INSERT
          As
            INSERT into information(学号,姓名)

           select i.学号,i.姓名
           from studentcourse sc,inserted i
           where sc.学号=i.学号

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值