---- Individuals - AFTER UPDATE,DELETE ----
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[OnIndividualsDelete]') and xtype = N'TR')
drop trigger [dbo].[OnIndividualsDelete]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[AfterIndividualsUpdate]') and xtype = N'TR')
drop trigger [dbo].[AfterIndividualsUpdate]
GO
CREATE TRIGGER AfterIndividualsUpdate ON [dbo].[Individuals] 
AFTER UPDATE,DELETE
AS
  if (SELECT Count(RegistrationAddressID) FROM DELETED) > 0
    DELETE FROM AddressBaseParts WHERE 
      AddressID in (select RegistrationAddressID from DELETED)
      AND ((select count(RegistrationAddressID) from inserted) = 0 OR   
      AddressID not in (select RegistrationAddressID from INSERTED))  
