insert 触发
create trigger trig_test
on scoreInfo
for insert
as
declare @testname varchar(50),@score int,@count int
select @testname=testname,@score=score from inserted
select @count =count(0) from totalinfo where testname=@testname
begin
if (@count=0)
insert into totalinfo (total,testname) values (@score,@testname)
else
update totalInfo set total=total+@score where testname=@testname
end
on scoreInfo
for insert
as
declare @testname varchar(50),@score int,@count int
select @testname=testname,@score=score from inserted
select @count =count(0) from totalinfo where testname=@testname
begin
if (@count=0)
insert into totalinfo (total,testname) values (@score,@testname)
else
update totalInfo set total=total+@score where testname=@testname
end
insert scoreinfo values('wang',800)
select * from scoreinfo
select * from totalInfo
select * from scoreinfo
select * from totalInfo