触发器之销售一件商品减少库存中该物品的数量 create trigger saleandupdate on Sale
for update,insert
as
declare @sFNO varchar(8),@insertedFNO varchar(8),@insertedNum int
select @insertedFNO=inserted.FNO,@insertedNum=inserted.SaleNum
from inserted
declare c2 cursor for select Store.FNO from Store
open c2
fetch next from c2 into @sFNO
while(@@FETCH_STATUS=0)
BEGIN
if(@sFNO=@insertedFNO)
begin
update Store
set StoreNum=StoreNum-@insertedNum
break
end
fetch next from c2 into @sFNO
END
close c2
deallocate c2