CREATE INDEX NSUNFE_006 ON NSUNFE (IDCONSULTADO ASC, IDAMBIENTENFE ASC, NRINSJURIEST ASC, NRNSU ASC)
/ 

CREATE INDEX NOTAFISCAL_098 ON NOTAFISCAL (CDFILIAL ASC, DTENTRSAID ASC, DTEMISSAO ASC, NRLANCTONF ASC, IDENTRSAIDOP ASC)
/

CREATE INDEX SINCRONIZACAONFE_1 ON SINCRONIZACAONFE (NRSINCRONIZANFE ASC)
/

CREATE TABLE RATEIOCUSTOIT 
(
    CDFILIAL    	  VARCHAR2(4) 	  NOT NULL ,
    NRLANCTONF  	  VARCHAR2(10) 	  NOT NULL ,
    NRSEQITPROD 	  VARCHAR2(4) 	  NOT NULL ,
    VRRATEIO    	  FLOAT,
	NRORG             NUMBER 	      DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
    IDATIVO           VARCHAR2(1)     DEFAULT 'S' 					NOT NULL
      CONSTRAINT CKC_IDATIVO_RATEIOCUSTOIT CHECK (IDATIVO IN ('S','N')),
    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 PK_RATEIOCUSTOIT PRIMARY KEY (CDFILIAL, NRLANCTONF, NRSEQITPROD),
		CONSTRAINT FKFIS00853ITEMPRODUTO FOREIGN KEY (CDFILIAL, NRLANCTONF, NRSEQITPROD)
			REFERENCES ITEMPRODUTO (CDFILIAL, NRLANCTONF, NRSEQITPROD) ON DELETE CASCADE  
)
/

CREATE INDEX FIS00853_FK ON RATEIOCUSTOIT(CDFILIAL ASC, NRLANCTONF ASC, NRSEQITPROD ASC)
/

CREATE TABLE RELACRATCUSTONF 
(
    CDFILIAL            VARCHAR2(4) 	NOT NULL ,
    NRLANCTONF          VARCHAR2(10) 	NOT NULL ,
    CDFILIDOCCOMP       VARCHAR2(4) 	NOT NULL ,
    NRLANCTODOCCOMP     VARCHAR2(10) 	NOT NULL ,
	NRORG               NUMBER 	      	DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
    IDATIVO             VARCHAR2(1)     DEFAULT 'S' 					NOT NULL
      CONSTRAINT CKC_IDATIVO_RELACRATCUSTONF CHECK (IDATIVO IN ('S','N')),
    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 PK_RELACRATCUSTONF PRIMARY KEY (CDFILIAL, NRLANCTONF, CDFILIDOCCOMP, NRLANCTODOCCOMP),
		CONSTRAINT FKFIS00854RELACRATCUSTONF FOREIGN KEY (CDFILIAL, NRLANCTONF)
			REFERENCES NOTAFISCAL (CDFILIAL, NRLANCTONF) ON DELETE CASCADE ,
		CONSTRAINT FKFIS00855RELACRATCUSTONFDOC FOREIGN KEY (CDFILIDOCCOMP, NRLANCTODOCCOMP)
			REFERENCES NOTAFISCAL (CDFILIAL, NRLANCTONF) 
)
/

CREATE INDEX FIS00854_FK ON RELACRATCUSTONF(CDFILIAL ASC, NRLANCTONF ASC)
/

CREATE INDEX FIS00855_FK ON RELACRATCUSTONF(CDFILIDOCCOMP ASC, NRLANCTODOCCOMP ASC)
/