ALTER TABLE PREVVNDPRODHR ADD IDORIGEMVENDA VARCHAR2(3) DEFAULT 'IDF' NOT NULL CONSTRAINT CKC_IDORIGEMVENDA_PREV CHECK (IDORIGEMVENDA IN ('SLA', 'DLV', 'THR', 'IDF'))

/

ALTER TABLE PREVVNDPRODHR ADD QTPROJVENDA VARCHAR2(10) DEFAULT '1' NOT NULL

/

DECLARE
    NAME_CONSTRAINT VARCHAR(20);
BEGIN
    SELECT CONSTRAINT_NAME INTO NAME_CONSTRAINT FROM USER_CONSTRAINTS WHERE CONSTRAINT_TYPE = 'P' AND TABLE_NAME = 'PREVVNDPRODHR';
    EXECUTE IMMEDIATE 'ALTER TABLE PREVVNDPRODHR DROP CONSTRAINT '||NAME_CONSTRAINT;
END;

/

ALTER TABLE PREVVNDPRODHR ADD CONSTRAINT PK_PREVVNDPRODHR PRIMARY KEY (NRSEQPREVPDV, CDFILIAL, CDLOJA, IDORIGEMVENDA, CDPRODUTO, DTPRODCONPDV, HORA)

/