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
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,希望能开拓一下思路
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
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,希望能开拓一下思路