请高手们帮忙小弟看下我的触发器问题出在哪里?
我的这个触发器用到三个表:库存信息、架存商品信息、下架记录
这个触发器要做的事情就是:当用户进行下架操作的时候,往下架记录表中插入一条下架记录。这时激活触发器,如果用户选择放回仓库(1)就把架存信息中的相应商品的架存数量减少需要下架的数量,库存则增加相应的数量。如果是销毁(0),则只需要减少架存商品的数量就好。
create table 库存信息(
条形码int,--8位
商品名称varchar(50),
--类别编号smallint not null,--5位
商店编号smallint,--库存地点,位
库存数量int,
primary key(条形码,商店编号),
foreign key(条形码) references 商品信息(条形码)
   on delete cascade   --当删除商品信息表中的元组是,级连删除库存信息表中相应元组
   on update cascade,  --当更新商品信息表中的元组是,级连更新库存信息表中相应元组
foreign key(商店编号) references 商店信息(商店编号)
   on delete cascade
   on update cascade,
);
create table 架存商品信息(
条形码int,--8位
--类别编号smallint not null,--5位
商店编号smallint,--所在商店,位
--店员编号smallint not null,--上架人,位
架存数量int not null,
primary key(条形码,商店编号),
foreign key(条形码) references 商品信息(条形码)
      on delete cascade
      on update cascade,
foreign key(商店编号) references 商店信息(商店编号)
      on delete cascade
      on update cascade,
);
create table 下架记录(
条形码int ,--8位
商店编号smallint,--5位
店员编号smallint,--5位,操作者
数量smallint not null,--不能超过当前架存数量
处理方式char(1) default(1) not null,--0销毁,返回仓库
时间datetime default(GetDate()),
primary key(商店编号,店员编号,条形码,时间),
foreign key(商店编号) references 商店信息(商店编号)
      on delete cascade
      on update cascade,
foreign key(店员编号) references 店员信息(店员编号)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
foreign key(条形码) references 商品信息(条形码)
      on delete cascade
      on update cascade,
)
/********************************************************************
 进行商品下架操作的时候,同时更新库存信息表和架存商品信息表中的相关信息
********************************************************************/
create trigger insert_reduce
on 下架记录after insert
as begin
       declare @newsq int,@oldsq int,@newpq int,@oldpq int,@NewNo int,@ShopId int,@ReduceQuantiry int,@dispose char;
       set @NewNo=(select 条形码from inserted); --获得新插入的条形码
       set @ShopId=(select 商店编号from inserted); --获得新插入的商店编号
       set @ReduceQuantiry = (select 数量from inserted); --获得新插入的数量
       set @dispose =(select 处理方式from inserted); --获得下架商品的处理方式    if @dispose = 1 --返回仓库
       begin
       select @oldsq = 库存数量from 库存信息where 条形码= @NewNo;
       select @oldpq = 架存数量from 架存商品信息where 条形码= @NewNo;
 
       set @newsq=@oldsq+@ReduceQuantiry;/*新库存数量= 旧库存数量+ 刚下架货物的数量*/
       set @newpq=@oldpq-@ReduceQuantiry;/*新架存数量= 旧架存商品数量- 刚下架货物的数量*/       if(@newpq <= 0)/*如果用户输入的下架货物的数量大于架存商品的数量*/
          begin
             set @newpq=0;/* 将架存商品数量更新为,即,将现有架存全部下架返回仓库*/
             set @newsq = @oldsq+@oldpq;/*新库存=旧库存+旧架存*/
             declare @NewEmpl int,@time datetime;
             set @NewEmpl =(select 店员编号from inserted);
             set @time =(select 时间from inserted);
             /*将实际的下架数量更新到下架记录中*/ 
             update 下架记录set 数量= @oldpq where 条形码= @NewNo and 店员编号= @NewEmpl and 时间= @time; 
          end;
       if(@newsq <= 0)
          begin
             set @newsq=0;
          end;
update 库存信息set 库存数量= @newsq where 条形码= @NewNo and 商店编号= @ShopId;
update 架存商品信息set 架存数量= @newpq where 条形码= @NewNo and 商店编号= @ShopId;
    end;
   
    if @dispose = 0 --销毁
       begin 
       select @oldpq = 架存数量from 架存商品信息where 条形码= @NewNo;
       set @newpq=@oldpq-@ReduceQuantiry;--架存商品数量减去要销毁货物的数量
       if(@newpq <= 0)/*如果用户输入的下架数量多于现有架存数量,则全部下架销毁*/
          begin
           set @newpq=0;
          end;
       update 架存商品信息set 架存数量= @newpq where 条形码= @NewNo and 商店编号=@ShopId;
       end;
end;
测试数据如下:insert into 下架记录(条形码,商店编号,店员编号,数量,处理方式) values(10000006,20000,10000,10,1);
 
执行完上面这一句插入语句后,下架记录的数据正常,但是结果显示影响了4行数据。架存数量由15变成了0 ,库存数量由20变成了37。 
/*******************************************************************/
insert into 下架记录(条形码,商店编号,店员编号,数量,处理方式) values(10000006,20000,10000,200,1);执行完上面的这语句之后,结果显示影响了4行数据。下架记录的数量是7,架存数量由15变成了0 ,库存数量由20变成了37。