MSSQLServer中的触发器问题(100分)

  • 主题发起人 主题发起人 beyboy
  • 开始时间 开始时间
B

beyboy

Unregistered / Unconfirmed
GUEST, unregistred user!
小弟,正做一供销存系统(Delphi+SQLServer7.0).本人负责存货一块,想通过原材料入
库单的入库,自动生成该原材料在原材料库存中的记录。即原材料库存中无该原材料
通过,新进入一批原材料。该原材料入库单的入库,触发一触发器,生成该原材料在库存
表中的记录。
Table BillMaterialsIntoStoreroom(BillNu,Time,MaterialNu,MaterialNa,MaterialAmount)
MaterialStoreroom(MaterialNu,MaterialNa,MaterialAmount)

 
CREATE TRIGGER BMTG ON BillMaterialsIntoStoreroom
FOR INSERT, UPDATE, DELETE AS

update MaterialStoreroom
set MaterialAmount = MaterialStoreroom.MaterialAmount + deleted.MaterialAmount
from MaterialStoreroom, deleted
where MaterialStoreroom.MaterialNu = deleted.MaterialNu

update MaterialStoreroom
set MaterialAmount = MaterialStoreroom.MaterialAmount - inserted.MaterialAmount
from MaterialStoreroom, inserted
where MaterialStoreroom.MaterialNu = inserted.MaterialNu

Insert Into MaterialStoreroom(MaterialNu,MaterialNa,MaterialAmount)
select MaterialNu,MaterialNa,MaterialAmount from inserted
where MaterialNu not in (select MaterialNu from MaterialStoreroom)



-- 试试!
 
接受答案了.
 
后退
顶部