create trigger tri_asb
on asb for insert
as
begin
declare @rk int
declare @ck int
declare @sid varchar(20)
select @sid=商品代码 ,@rk =入库数量,@ck=出库数量 from inserted
if not exists(select * from asb where 商品代码=@sid)
insert into bsb(商品代码,数量) values(@sid,@rk-@ck)
else
update bsb set 数量=数量+(@rk-@ck) where 商品代码=@sid
end