SET TERM ^ ;

CREATE OR ALTER trigger ttbpdv_cfe_a01d for tbpdv_cfe
active after delete position 1
AS
BEGIN
    UPDATE TBPDV_CFE T SET T.NF_ACOMPANHAMENTO_ID = 0 WHERE T.NF_ACOMPANHAMENTO_ID = OLD.ID;
    DELETE FROM TBPDV_CFE_ITEM T WHERE T.PDV_CFE_ID = OLD.ID;
    DELETE FROM TBPDV_CFE_ITEM_SALDO T WHERE T.PDV_CFE_ID = OLD.ID;
    DELETE FROM TBPDV_CFE_FORMA_PAGAMENTO T WHERE T.PDV_CFE_ID = OLD.ID;
    DELETE FROM TBCHEQUE T WHERE T.PDV_CFE_ID = OLD.ID;
END
^

SET TERM ; ^

