CREATE TABLE HISTPEDCONS (
   CDFILIAL          VARCHAR2(4)   	 NOT NULL,   
   NRVENDAREST       VARCHAR2(10)  	 NOT NULL,
   NRCOMANDA         VARCHAR2(10)  	 NOT NULL,   
   NRSEQHISTPED      VARCHAR2(3)     NOT NULL,
   CDLOJA            VARCHAR2(10)  	 NULL,
   IDHISTPEDCONS     VARCHAR2(1)  	 NULL,
   DSHISTPEDCONS     VARCHAR2(100) 	 NULL,
   DTHRHISTPEDCONS   DATE 	         NULL,
   NRORG             NUMBER 	     DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 	NOT NULL,
   IDATIVO           VARCHAR2(1)     DEFAULT 'S'								NOT NULL,
   DTINCLUSAO        DATE            DEFAULT SYSDATE,
   DTULTATU          DATE            DEFAULT SYSDATE,
   NRORGINCLUSAO     NUMBER          DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg')	NULL,
   CDOPERINCLUSAO    VARCHAR2(12)    DEFAULT '1' 					NULL,
   NRORGULTATU       NUMBER          DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg')	NULL,
   CDOPERULTATU      VARCHAR2(12)    DEFAULT '1',
	  CONSTRAINT CKC_IDATIVO_HISTPEDCONS CHECK (IDATIVO IN ('S','N')),
	  CONSTRAINT CKC_IDHISTPEDCONS_HISTPEDCONS CHECK (IDHISTPEDCONS IN ('P','R','S','F','E','C')),
    CONSTRAINT PK_HISTPEDCONS PRIMARY KEY (CDFILIAL, NRVENDAREST, NRCOMANDA, NRSEQHISTPED)
)
/

ALTER TABLE HISTPEDCONS
   ADD CONSTRAINT FKVND00843COMANDAVEN FOREIGN KEY (CDFILIAL, NRVENDAREST, NRCOMANDA)
      REFERENCES COMANDAVEN (CDFILIAL, NRVENDAREST, NRCOMANDA)
/

CREATE INDEX VND00843_FK ON HISTPEDCONS (CDFILIAL ASC, NRVENDAREST ASC, NRCOMANDA ASC)
/