CREATE TABLE PREVCONSINF
(
	NRPREVCONSINF       NUMBER                              NOT NULL,
   CDPREVCONSINF        VARCHAR2(20)                        NOT NULL,
   CDFILIAL             VARCHAR2(04)                         NOT NULL,
   DTGERACAO            DATE                                NOT NULL,   
   DTINIPREVCONSINF     DATE                                NOT NULL,
   DTFIMPREVCONSINF     DATE                                NOT NULL,   
   NRORG                NUMBER         	DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg')            NOT NULL,
   IDATIVO              VARCHAR2(01)    DEFAULT 'S'          NOT NULL
		CONSTRAINT CKC_IDATIVO_PREVCONSINF CHECK (IDATIVO IN ('S', 'N')),
   DTINCLUSAO           DATE                                NULL,
   DTULTATU             DATE                                NULL,
   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'          NULL,
		CONSTRAINT PK_PREVCONSINF PRIMARY KEY (NRPREVCONSINF)
)
/

ALTER TABLE PREVCONSINF ADD
   CONSTRAINT FKCOC00767FILIAL FOREIGN KEY (CDFILIAL)
      REFERENCES FILIAL (CDFILIAL)
/

CREATE INDEX PREVCONSINF_01 ON PREVCONSINF (CDFILIAL, DTGERACAO)
/

CREATE INDEX PREVCONSINF_02 ON PREVCONSINF (CDFILIAL, DTINCLUSAO)
/

CREATE TABLE INSUMOPREVCONSINF
(
   NRINSUMOPREVCONSINF  NUMBER                              NOT NULL,
   NRPREVCONSINF        NUMBER                              NOT NULL,
   CDPRODUTO            VARCHAR2(10)                        NOT NULL,
   QTINSUMOCALC         FLOAT                               NOT NULL,
   NRORG                NUMBER          DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg')            NOT NULL,
   IDATIVO              VARCHAR2(01)    DEFAULT 'S'          NOT NULL
		CONSTRAINT CKC_IDATIVO_INSUMOPREVCONSINF CHECK (IDATIVO IN ('S', 'N')),
   DTINCLUSAO           DATE                                NULL,
   DTULTATU             DATE                                NULL,
   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'          NULL,
		CONSTRAINT PK_INSUMOPREVCONSINF PRIMARY KEY (NRINSUMOPREVCONSINF),
		CONSTRAINT UN_INSUMOPREVCONSINF UNIQUE (NRPREVCONSINF, CDPRODUTO)
)
/

ALTER TABLE INSUMOPREVCONSINF ADD
   CONSTRAINT FKCOC00768PREVCONSINF FOREIGN KEY (NRPREVCONSINF)
      REFERENCES PREVCONSINF (NRPREVCONSINF)
/

CREATE INDEX FKCOC00768PREVCONSINF ON INSUMOPREVCONSINF (NRPREVCONSINF)
/

ALTER TABLE INSUMOPREVCONSINF ADD
   CONSTRAINT FKCOC00769PRODUTO FOREIGN KEY (CDPRODUTO)
      REFERENCES PRODUTO (CDPRODUTO)
/

CREATE INDEX FKCOC00769PRODUTO ON INSUMOPREVCONSINF (CDPRODUTO)
/

CREATE TABLE DESTPREVCONSINF
(
   NRDESTPREVCONSINF    NUMBER                              NOT NULL,
   NRINSUMOPREVCONSINF  NUMBER                              NOT NULL,
   CDFILIAL             VARCHAR2(04)                         NOT NULL,
   CDCIA                VARCHAR2(04)                         NOT NULL,   
   NRVOO                VARCHAR2(05)                         NOT NULL,
   CDTRECHO             VARCHAR2(04)                         NOT NULL,
   DTATENDIMENTO        DATE                                NOT NULL,
   DTPRODUCAO           DATE                                NOT NULL,
   NRSERVICOCIAFILIP    NUMBER                              NOT NULL,
   CDMANCIA             VARCHAR2(04)                         NOT NULL,
   NRSERVICOCIAFILI     NUMBER                              NOT NULL,
   CDCLASSE             VARCHAR2(04)                         NOT NULL,
   CDSUBGRU             VARCHAR2(10)                        NOT NULL,
   NRSEQSUBGRUSEMAM     NUMBER                              NOT NULL,
   CDCICLO              VARCHAR2(04)                         NOT NULL,
   NRTIPOPROD           NUMBER                              NOT NULL,
   NRTIPONEGOCIOINF     NUMBER                              NOT NULL,
   CDRECEITAMENU        VARCHAR2(10)                        NULL,
   CDRECEITADEST        VARCHAR2(10)                        NULL,
   CDRECEITA            VARCHAR2(10)                        NULL,
   CDSETOR              VARCHAR2(04)                         NULL,
   NRTURNO              VARCHAR2(02)                         NULL,
   NRCATEGORIAPROD      NUMBER                              NULL,
   NRSUBCATEGORIAPROD   NUMBER                              NULL,
   QTINSUMOCALC         FLOAT                               NOT NULL,
   NRORG                NUMBER         	DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg')            NOT NULL,
   IDATIVO              VARCHAR2(01)    DEFAULT 'S'          NOT NULL
		CONSTRAINT CKC_IDATIVO_DESTPREVCONSINF CHECK (IDATIVO IN ('S', 'N')),
   DTINCLUSAO           DATE                                NULL,
   DTULTATU             DATE                                NULL,
   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'          NULL,
		CONSTRAINT PK_DESTPREVCONSINF PRIMARY KEY (NRDESTPREVCONSINF)
)
/

ALTER TABLE DESTPREVCONSINF ADD
   CONSTRAINT FKCOC00770INSUMOPREVCONSINF FOREIGN KEY (NRINSUMOPREVCONSINF)
      REFERENCES INSUMOPREVCONSINF (NRINSUMOPREVCONSINF)
/

CREATE INDEX FKCOC00770INSUMOPREVCONSINF ON DESTPREVCONSINF (NRINSUMOPREVCONSINF)
/

ALTER TABLE DESTPREVCONSINF ADD
   CONSTRAINT FKCOC00771VOOTRECHO FOREIGN KEY (CDFILIAL, CDCIA, NRVOO, CDTRECHO)
      REFERENCES VOOTRECHO (CDFILIAL, CDCIA, NRVOO, CDTRECHO)
/

CREATE INDEX FKCOC00771VOOTRECHO ON DESTPREVCONSINF (CDFILIAL, CDCIA, NRVOO, CDTRECHO)
/

ALTER TABLE DESTPREVCONSINF ADD
   CONSTRAINT FKCOC00772MANUALCIAM FOREIGN KEY (CDFILIAL, CDCIA, CDMANCIA)
      REFERENCES MANUALCIAM (CDFILIAL, CDCIA, CDMANCIA)
/

CREATE INDEX FKCOC00772MANUALCIAM ON DESTPREVCONSINF (CDFILIAL, CDCIA, CDMANCIA)
/

ALTER TABLE DESTPREVCONSINF ADD
   CONSTRAINT FKCOC00773SERVICOCIAFILI FOREIGN KEY (CDFILIAL, CDCIA, NRSERVICOCIAFILI)
      REFERENCES SERVICOCIAFILI (CDFILIAL, CDCIA, NRSERVICOCIAFILI)
/

CREATE INDEX FKCOC00773SERVICOCIAFILI ON DESTPREVCONSINF (CDFILIAL, CDCIA, NRSERVICOCIAFILI)
/

ALTER TABLE DESTPREVCONSINF ADD
   CONSTRAINT FKCOC00774SERVICOCIAFILI FOREIGN KEY (CDFILIAL, CDCIA, NRSERVICOCIAFILIP)
      REFERENCES SERVICOCIAFILI (CDFILIAL, CDCIA, NRSERVICOCIAFILI)
/

CREATE INDEX FKCOC00774SERVICOCIAFILI ON DESTPREVCONSINF (CDFILIAL, CDCIA, NRSERVICOCIAFILIP)
/

ALTER TABLE DESTPREVCONSINF ADD
   CONSTRAINT FKCOC00775CLASSE FOREIGN KEY (CDCLASSE)
      REFERENCES CLASSE (CDCLASSE)
/

CREATE INDEX FKCOC00775CLASSE ON DESTPREVCONSINF (CDCLASSE)
/

ALTER TABLE DESTPREVCONSINF ADD
   CONSTRAINT FKCOC00776SUBGRUPOM FOREIGN KEY (CDSUBGRU)
      REFERENCES SUBGRUPOM (CDSUBGRU)
/

CREATE INDEX FKCOC00776SUBGRUPOM ON DESTPREVCONSINF (CDSUBGRU)
/

ALTER TABLE DESTPREVCONSINF ADD
   CONSTRAINT FKCOC00777CICLO FOREIGN KEY (CDCICLO)
      REFERENCES CICLO (CDCICLO)
/

CREATE INDEX FKCOC00777CICLO ON DESTPREVCONSINF (CDCICLO)
/

ALTER TABLE DESTPREVCONSINF ADD
   CONSTRAINT FKCOC00778TIPOPROD FOREIGN KEY (NRTIPOPROD)
      REFERENCES TIPOPROD (NRTIPOPROD)
/

CREATE INDEX FKCOC00778TIPOPROD ON DESTPREVCONSINF (NRTIPOPROD)
/

ALTER TABLE DESTPREVCONSINF ADD
   CONSTRAINT FKCOC00779TIPONEGOCIOINF FOREIGN KEY (NRTIPONEGOCIOINF)
      REFERENCES TIPONEGOCIOINF (NRTIPONEGOCIOINF)
/

CREATE INDEX FKCOC00779TIPONEGOCIOINF ON DESTPREVCONSINF (NRTIPONEGOCIOINF)
/

ALTER TABLE DESTPREVCONSINF ADD
   CONSTRAINT FKCOC00780RECEITAM FOREIGN KEY (CDRECEITAMENU)
      REFERENCES RECEITAM (CDRECEITA)
/

CREATE INDEX FKCOC00780RECEITAM ON DESTPREVCONSINF (CDRECEITAMENU)
/

ALTER TABLE DESTPREVCONSINF ADD
   CONSTRAINT FKCOC00781RECEITAM FOREIGN KEY (CDRECEITADEST)
      REFERENCES RECEITAM (CDRECEITA)
/

CREATE INDEX FKCOC00781RECEITAM ON DESTPREVCONSINF (CDRECEITADEST)
/

ALTER TABLE DESTPREVCONSINF ADD
   CONSTRAINT FKCOC00782RECEITAM FOREIGN KEY (CDRECEITA)
      REFERENCES RECEITAM (CDRECEITA)
/

CREATE INDEX FKCOC00782RECEITAM ON DESTPREVCONSINF (CDRECEITA)
/

ALTER TABLE DESTPREVCONSINF ADD
   CONSTRAINT FKCOC00783SETOR FOREIGN KEY (CDSETOR)
      REFERENCES SETOR (CDSETOR)
/

CREATE INDEX FKCOC00783SETOR ON DESTPREVCONSINF (CDSETOR)
/

ALTER TABLE DESTPREVCONSINF ADD
   CONSTRAINT FKCOC00784TURNO FOREIGN KEY (NRTURNO)
      REFERENCES TURNO (NRTURNO)
/

CREATE INDEX FKCOC00784TURNO ON DESTPREVCONSINF (NRTURNO)
/

ALTER TABLE DESTPREVCONSINF ADD
   CONSTRAINT FKCOC00785CATEGORIAPROD FOREIGN KEY (NRCATEGORIAPROD)
      REFERENCES CATEGORIAPROD (NRCATEGORIAPROD)
/

CREATE INDEX FKCOC00785CATEGORIAPROD ON DESTPREVCONSINF (NRCATEGORIAPROD)
/

ALTER TABLE DESTPREVCONSINF ADD
   CONSTRAINT FKCOC00786CATEGORIAPROD FOREIGN KEY (NRSUBCATEGORIAPROD)
      REFERENCES CATEGORIAPROD (NRCATEGORIAPROD)
/

CREATE INDEX FKCOC00786CATEGORIAPROD ON DESTPREVCONSINF (NRSUBCATEGORIAPROD)
/

CREATE INDEX DESTPREVCONSINF_18 ON DESTPREVCONSINF(NRINSUMOPREVCONSINF, DTPRODUCAO, CDRECEITA)
/

CREATE INDEX DESTPREVCONSINF_19 ON DESTPREVCONSINF(NRINSUMOPREVCONSINF, DTPRODUCAO, CDFILIAL, CDCIA, CDMANCIA, NRSERVICOCIAFILI, CDCLASSE, CDSUBGRU, NRSEQSUBGRUSEMAM, CDCICLO)
/