CREATE TRIGGER 名 on 表
INSTEAD OF INSERT
AS
BEGIN
  INSERT INTO 表  SELECT a,b,a+c FROM inserted
END

解决方案 »

  1.   

    CREATE TRIGGER [trig_name] ON [dbo].[abcd] 
    instead of INSERT
    AS
    begin
    declare @num int
    declare @d int
    select @d=d from inserted
    select @num=sum(B) from 表  where d<=@d
    INSERT INTO 表  SELECT a,b,@num+b,d FROM inserted
    end
      

  2.   

    CREATE TRIGGER [trig_name] ON [dbo].[abcd] 
    for INSERT
    AS
    begin
    declare @num int
    declare @d int
    select @d=d from inserted
    select @num=sum(B) from 表  where d<@d
    update 表 set c=b+@num  FROM inserted,表 where inserted.d=表.d 
    end
    当然,用for insert 比不上用instead of INSERT,希望能开拓一下思路