SET TERM ^ ;

CREATE OR ALTER trigger ttbmodelo_kit_b01d for tbmodelo_kit
active before delete position 0
AS
BEGIN
   IF(OLD.ID IS NOT NULL)then
   BEGIN
       DELETE FROM TBMODELO_KIT_ITEM A WHERE A.MODELO_KIT_ID = OLD.ID;
       DELETE FROM TBPRODUTO P WHERE P.MODELO_CODIGO = OLD.MODELO_ID AND P.COR_CODIGO = OLD.COR_ID;
       DELETE FROM TBEAN E WHERE E.MODELO_ID = OLD.MODELO_ID AND E.COR_ID = OLD.COR_ID AND E.TAMANHO = OLD.TAMANHO;
--       DELETE FROM TBMODELO_COR MC WHERE MC.MODELO_ID = OLD.MODELO_ID AND MC.COR_ID = OLD.COR_ID;
--       DELETE FROM TBCOR C WHERE C.CODIGO = OLD.COR_ID;
   END
END
^

SET TERM ; ^

