ALTER TABLE FILIALCADA ADD IDCONSISTVRAPROV VARCHAR2(1) DEFAULT 'T' NULL
   CONSTRAINT CKC_ALC_IDCONSISTVRAPROV CHECK (IDCONSISTVRAPROV IS NULL OR (IDCONSISTVRAPROV IN ('T','M')))  
/

CREATE TABLE MODELORELAF
(
	NRMODELORELAF 		INTEGER 		NOT NULL,
	CDFILIAL            VARCHAR2(4),
	IDDSRESPONFAT 		CHAR(1),
	IDDSENDERECOFAT     CHAR(1), 
	IDNRINSJURFAT     	CHAR(1),
	IDDSRESPONCOB 		CHAR(1),
	IDDSENDERECOCOB     CHAR(1),
	IDNRINSJURCOB     	CHAR(1),  
	IDDSENDERECOENTR    CHAR(1),
	IDCNPJENTR     		CHAR(1),
	TEXTMODELRELAF 		CLOB,
    NRORG 				NUMBER 			DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
	IDATIVO 			VARCHAR2(1) 	DEFAULT 'S' NOT NULL,
		CONSTRAINT CKC_IDATIVO_MODELORELAF 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',
		CONSTRAINT PK_NRMODELORELAF PRIMARY KEY (NRMODELORELAF)
    )
/

CREATE INDEX CMP00597_FK ON MODELORELAF (CDFILIAL ASC)
/

ALTER TABLE MODELORELAF  
	ADD CONSTRAINT FKCMP00597FILIAL FOREIGN KEY(CDFILIAL) 
		REFERENCES FILIAL(CDFILIAL)
/

DROP SEQUENCE SEQ_NRMODELORELAF
/

CREATE SEQUENCE SEQ_NRMODELORELAF INCREMENT BY 1 MINVALUE 1
/

ALTER TABLE PARASUPRI ADD IDUTINDICECOL VARCHAR2(1) 
	CONSTRAINT CKC_IDUTINDICECOL CHECK (IDUTINDICECOL IN ('S','N'))
/

ALTER TABLE ITEMCOLE ADD VRINDICEITMCOL FLOAT
/

ALTER TABLE ITEMAUTF ADD VRINDICEITMAF FLOAT
/

ALTER TABLE COLETAPR ADD CDTPINDICECOL VARCHAR2(1) 
	CONSTRAINT CKC_CDTPINDICECOL CHECK (CDTPINDICECOL IN ('1','2', '3'))
/

ALTER TABLE COLETAPR ADD IDPERVALORCOL VARCHAR2(1) 
	CONSTRAINT CKC_IDPERVALORCOL CHECK (IDPERVALORCOL IN ('1','2'))
/

ALTER TABLE COLETAPR ADD CDINDICECOL VARCHAR2(4)
/

ALTER TABLE COLETAPR ADD DTREFINDCOL DATE
/

ALTER TABLE COLETAPR ADD 
	CONSTRAINT FKCMP00598MOVINDICE FOREIGN KEY (CDTPINDICECOL, IDPERVALORCOL, CDINDICECOL, DTREFINDCOL)
                  REFERENCES MOVINDICE(CDTPINDICE, IDPERVALOR, CDINDICE, DTREFIND)
/

CREATE INDEX CMP00598_FK ON COLETAPR(CDTPINDICECOL, IDPERVALORCOL, CDINDICECOL, DTREFINDCOL) 
/


ALTER TABLE ITMAPURPREC ADD CDTPINDICEAPU VARCHAR2(1) 
	CONSTRAINT CKC_CDTPINDICEAPU CHECK (CDTPINDICEAPU IN ('1','2','3'))
/

ALTER TABLE ITMAPURPREC ADD IDPERVALORAPU VARCHAR2(1) 
	CONSTRAINT CKC_IDPERVALORAPU CHECK (IDPERVALORAPU IN ('1','2'))
/

ALTER TABLE ITMAPURPREC ADD CDINDICEAPU VARCHAR2(4)
/

ALTER TABLE ITMAPURPREC ADD DTREFINDAPU DATE
/

ALTER TABLE ITMAPURPREC ADD VRINDICEAPU FLOAT 
/

ALTER TABLE ITMAPURPREC ADD 
	CONSTRAINT FKCMP00599MOVINDICE FOREIGN KEY (CDTPINDICEAPU, IDPERVALORAPU, CDINDICEAPU, DTREFINDAPU)
		REFERENCES MOVINDICE(CDTPINDICE, IDPERVALOR, CDINDICE, DTREFIND)
/

CREATE INDEX CMP00599_FK ON ITMAPURPREC(CDTPINDICEAPU, IDPERVALORAPU, CDINDICEAPU, DTREFINDAPU) 
/

ALTER TABLE AUTOFORNE ADD CDTPINDICEAF VARCHAR2(1) 
	CONSTRAINT CKC_CDTPINDICEAF CHECK (CDTPINDICEAF IN ('1','2','3'))
/

ALTER TABLE AUTOFORNE ADD IDPERVALORAF VARCHAR2(1) 
	CONSTRAINT CKC_IDPERVALORAF CHECK (IDPERVALORAF IN ('1','2'))
/

ALTER TABLE AUTOFORNE ADD CDINDICEAF VARCHAR2(4)
/

ALTER TABLE AUTOFORNE ADD DTREFINDAF DATE
/

ALTER TABLE AUTOFORNE ADD 
	CONSTRAINT FKCMP00600MOVINDICE FOREIGN KEY (CDTPINDICEAF, IDPERVALORAF, CDINDICEAF, DTREFINDAF)
		REFERENCES MOVINDICE(CDTPINDICE, IDPERVALOR, CDINDICE, DTREFIND)
/

CREATE INDEX CMP00600_FK ON AUTOFORNE(CDTPINDICEAF, IDPERVALORAF, CDINDICEAF, DTREFINDAF)