---- Организация - AFTER UPDATE,DELETE ----
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[OnОрганизацияDelete]') and xtype = N'TR')
drop trigger [dbo].[OnОрганизацияDelete]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[AfterОрганизацияUpdate]') and xtype = N'TR')
drop trigger [dbo].[AfterОрганизацияUpdate]
GO
CREATE TRIGGER AfterОрганизацияUpdate ON [dbo].[Организация] 
AFTER UPDATE,DELETE
AS
  if (SELECT Count(Код_юридического_адреса) FROM DELETED) > 0
    DELETE FROM AddressBaseParts WHERE 
      AddressID in (select Код_юридического_адреса from DELETED)
      AND ((select count(Код_юридического_адреса) from inserted) = 0 OR   
      AddressID not in (select Код_юридического_адреса from INSERTED))  
