SET TERM ^ ;

CREATE trigger ttbficha_custo_b01d for tbficha_custo
active before delete position 1
AS
BEGIN
    IF(OLD.ID > 0) THEN
    BEGIN

        DELETE FROM TBFICHA_CUSTO_MP T WHERE T.FICHA_CUSTO_ID = OLD.ID;
        DELETE FROM TBFICHA_CUSTO_SERVICO T WHERE T.FICHA_CUSTO_ID = OLD.ID;
        DELETE FROM TBFICHA_CUSTO_TEMPO T WHERE T.FICHA_CUSTO_ID = OLD.ID;
        DELETE FROM TBFICHA_CUSTO_CALENDARIO T WHERE T.FICHA_CUSTO_ID = OLD.ID;
        DELETE FROM TBFICHA_CUSTO_CONSUMO T WHERE T.FICHA_CUSTO_ID = OLD.ID;
        DELETE FROM TBFICHA_CUSTO_TRIBUTACOES T WHERE T.FICHA_CUSTO_ID = OLD.ID;

    END
END
^

SET TERM ; ^

