CREATE TRIGGER [update_compute] ON [dbo].[t] 
FOR INSERT, UPDATE
AS
begin
if upadte(b)
set set t.c =  t.a + t.b
if update(a)
set t.c =  t.a + t.b
end

解决方案 »

  1.   

    CREATE TRIGGER [update_compute] ON [dbo].[t] 
    FOR INSERT, UPDATE
    AS
    begin
            update t
            set c =  b.a + b.b from t a,inserted b where a.c=b.c
    end
    试一下
      

  2.   

    CREATE TRIGGER [update_compute] ON [dbo].[t] 
    FOR INSERT, UPDATE
    AS
    begin
    if update(a) or update(b)
    set t.c = t.a + t.b
    end
      

  3.   

    yesterday2000(一笑而过) 说的 很对 用系统里的 虚表就可以了
      

  4.   

    若有主键的话, 那可以用出发器:
    create table t_test (a int,b int,c int)假如字段a为主键:create trigger tr_test on t_test
    for insert,update
    as
    begin
    update t_a set t_a.c=isnull(t_b.b,0)+isnull(t_b.a,0) from t_test as t_a,inserted as t_b where t_a.a=t_b.a
    end
      

  5.   

    即:create trigger tr_test on t_test
    for insert,update
    as
    begin
    update t_a set t_a.c=isnull(t_b.b,0)+isnull(t_b.a,0) from t_test as t_a,inserted as t_b where t_a.主键=t_b.主键
    end
      

  6.   

    菜鸟我也有同感,但我的情况是:我只想计算新插入或者修改了的行的目的是为了提高效率,如果用where语句(当然比对整张表的所有行进行计算的效率要高),它不还是要每一行都比较一下吗?
    有更好的方法吗?
      

  7.   

    如果没有主键还要实现此功能
    insert into t values(x,y,x+y)
    这不就行了吗?