SET TERM ^ ;
ALTER TABLE TBPDV_REPRESENTANTE
ADD PADRAO_PDV_PRE_PEDIDO INTEGER
DEFAULT 0^

CREATE OR ALTER TRIGGER TTBPDV_REPRESENTANTE_B01I FOR TBPDV_REPRESENTANTE
ACTIVE BEFORE INSERT POSITION 0
AS
BEGIN
  IF(NEW.ID IS NULL) THEN
  BEGIN
    NEW.ID = GEN_ID(GTBPDV_REPRESENTANTE,1);
  END

  IF(COALESCE(NEW.PADRAO_PDV_PRE_PEDIDO,0) = 1)THEN
  BEGIN
     UPDATE TBPDV_REPRESENTANTE A
        SET A.PADRAO_PDV_PRE_PEDIDO = 0
        WHERE A.ID <> NEW.ID;
  END
END^
^ SET TERM ; ^