首页新闻找找看学习计划

求:SQL一张表插入值另一张表数据立即更新的触发器或函数...

0
悬赏园豆:10 [已解决问题] 解决于 2014-04-25 15:56

有三张表,a,b,c

分别有字段

a:num,sumcash

b:num,val

c:num,F_val

需求:当表b插入一条数据时,表a的sumcash等于sumcash+val(数值),条件是num等于num

,当表c插入一条数据时,表a的sumcash等于sumcash-F_val(数值),条件是num等于num 。。。 求 ~~~ help me ... SOS ...没豆豆了 。。

Heaven空白的主页 Heaven空白 | 初学一级 | 园豆:3
提问于:2014-04-15 10:57
< >
分享
最佳答案
0
create trigger tri_a_b
on b 
after insert
as
    declare @id int
    declare @val int
    select @id = num from inserted;
    select @val = val from inserted;
    update a set sumcash = sumcash + @val where a.num = @id
go


alter trigger tri_a_c
on c
after insert
as
    declare @id int
    declare @val int
    select @id = num from inserted;
    select @val = f_val from inserted;
    update a set sumcash = sumcash - @val where a.num = @id
go
收获园豆:10
轻狂の书生 | 小虾三级 |园豆:1040 | 2014-04-15 17:25

... 我自己琢磨出来了  不过还是谢谢 ~~~

Heaven空白 | 园豆:3 (初学一级) | 2014-04-25 15:56
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册