---- ConsumingObjects - AFTER UPDATE,DELETE ----
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[OnConsumingObjectsDelete]') and xtype = N'TR')
drop trigger [dbo].[OnConsumingObjectsDelete]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[AfterConsumingObjectsUpdate]') and xtype = N'TR')
drop trigger [dbo].[AfterConsumingObjectsUpdate]
GO
CREATE TRIGGER AfterConsumingObjectsUpdate ON [dbo].[ConsumingObjects] 
AFTER UPDATE, DELETE
AS
  SET NOCOUNT ON
  if (SELECT Count(AddressID) FROM DELETED) > 0
    DELETE FROM AddressExtraParts WHERE 
      ExtraPartID in (select AddressID from DELETED)
      AND ((select count(AddressID) from inserted) = 0 OR   
      ExtraPartID not in (select AddressID from INSERTED))  
  SET NOCOUNT OFF