//增加
CREATE TRIGGER [dc_jhbid_tr] ON [dbo].[dc_jhbid]
FOR INSERT
AS
update b set b.dglsl=b.dglsl-i.dsl from dc_htdd b,inserted i
where i.dhtbm=b.dhtbm and i.dcpbm=b.dhtbm
//修改
CREATE TRIGGER [dc_jhbid_tr] ON [dbo].[dc_jhbid]
FOR UPDATEAS
IF UPDATE (dsl) -- is update
update b set b.dglsl=b.dglsl-(d.dsl-i.dsl)
from dc_htdd b,inserted i,deleted d
where i.dhtbm =b.dhtbm and i.dhtbm=b.dcpbm and d.dhtbm=b.dhtbm and d.dhtbm =b.dcpbm
//删除
CREATE TRIGGER [dc_jhbid_tr] ON [dbo].[dc_jhbid]
FOR delete
update b set b.dglsl=b.dglsl-d.dsl from dc_htdd b,deleted d
where d.dhtbm=b.dhtbm and d.dhtbm =b.dcpbm
CREATE TRIGGER [dc_jhbid_tr] ON [dbo].[dc_jhbid]
FOR INSERT
AS
update b set b.dglsl=b.dglsl-i.dsl from dc_htdd b,inserted i
where i.dhtbm=b.dhtbm and i.dcpbm=b.dhtbm
//修改
CREATE TRIGGER [dc_jhbid_tr] ON [dbo].[dc_jhbid]
FOR UPDATEAS
IF UPDATE (dsl) -- is update
update b set b.dglsl=b.dglsl-(d.dsl-i.dsl)
from dc_htdd b,inserted i,deleted d
where i.dhtbm =b.dhtbm and i.dhtbm=b.dcpbm and d.dhtbm=b.dhtbm and d.dhtbm =b.dcpbm
//删除
CREATE TRIGGER [dc_jhbid_tr] ON [dbo].[dc_jhbid]
FOR delete
update b set b.dglsl=b.dglsl-d.dsl from dc_htdd b,deleted d
where d.dhtbm=b.dhtbm and d.dhtbm =b.dcpbm
select @ninsRows=count(*0 from inserted --add this statement
FOR INSERT, UPDATE, DELETE
AS
DECLARE @nCount int
DECLARE @nInsRows int SELECT @nCount = COUNT(*) FROM DELETED
select @ninsRows=count(*) from inserted --add this statement IF (@nInsRows > 0 AND @nCount > 0) --is insert
update b set b.dglsl=b.dglsl-i.dsl from dc_htdd b,inserted i
where i.dhtbm=b.dhtbm and i.dcpbm=b.dhtbm
IF update(dc_jhbid) -- is update
update b set b.dglsl=b.dglsl-(d.dsl-i.dsl)
from dc_htdd b,inserted i,deleted d
where i.dhtbm =b.dhtbm and i.dhtbm=b.dcpbm and d.dhtbm=b.dhtbm and d.dhtbm =b.dcpbm
IF (@nInsRows = 0 AND @nCount > 0) --is insert
update b set b.dglsl=b.dglsl+d.dsl from dc_htdd b,deleted d
where d.dhtbm=b.dhtbm and d.dcpbm=b.dhtbm
看看
http://www.csdn.net/expert/topic/646/646270.xml?temp=.6881983
也许对你有帮助。