CREATE TABLE ANX_OBSHISTFILIAL (
   NRANEXOHIST	 	NUMBER 			NOT NULL,
   CDFILIAL 		VARCHAR2(4) 		NOT NULL,
   DTHISTFIL 		DATE 			NOT NULL,
   CDOPERADOR 		VARCHAR2(12) 		NOT NULL,
   CDDESCOBSFILIAL 	VARCHAR2(2) 		NOT NULL,
   DSDOCUMENTOANEXO 	VARCHAR2(2000) 		NOT NULL,
   DOCUMENTOANEXO 	VARCHAR2(2000) 		NOT NULL,
   NRORG                       	NUMBER DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
   IDATIVO                    	VARCHAR2(1)     		DEFAULT 'S' NOT NULL
      CONSTRAINT CKC_IDATIVO_ANX_OBSHISTFILIAL 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_ANX_OBSHISTFILIAL PRIMARY KEY (NRANEXOHIST)
)
/

ALTER TABLE ANX_OBSHISTFILIAL ADD
	CONSTRAINT FKPLA01182OBSHISTFILIAL FOREIGN KEY (CDFILIAL,DTHISTFIL,CDOPERADOR,CDDESCOBSFILIAL)
		REFERENCES OBSHISTFILIAL (CDFILIAL,DTHISTFIL,CDOPERADOR,CDDESCOBSFILIAL) ON DELETE CASCADE
/

CREATE INDEX PLA01182_FK ON ANX_OBSHISTFILIAL (CDFILIAL ASC,DTHISTFIL ASC,CDOPERADOR ASC,CDDESCOBSFILIAL ASC)
/

ALTER TABLE VIGLIMPESERGR ADD CDDESCOBSFILIAL VARCHAR2(2) NULL
/

CREATE INDEX PLA01183_FK ON VIGLIMPESERGR (CDDESCOBSFILIAL ASC) 
/

ALTER TABLE VIGLIMPESERGR ADD 
	CONSTRAINT FKPLA01183DESCOBSFILIAL FOREIGN KEY (CDDESCOBSFILIAL) 
		REFERENCES DESCOBSFILIAL (CDDESCOBSFILIAL) ON DELETE SET NULL
/

ALTER TABLE VIGFREQPRATMES ADD CDDESCOBSFILIAL VARCHAR2(2) NULL
/

CREATE INDEX PLA01184_FK ON VIGFREQPRATMES  (CDDESCOBSFILIAL ASC) 
/

ALTER TABLE VIGFREQPRATMES ADD 
	CONSTRAINT FKPLA01184DESCOBSFILIAL FOREIGN KEY (CDDESCOBSFILIAL) 
		REFERENCES DESCOBSFILIAL (CDDESCOBSFILIAL) ON DELETE SET NULL
/

ALTER TABLE VIGFREQGRPRATMES ADD CDDESCOBSFILIAL VARCHAR2(2) NULL
/

CREATE INDEX PLA01185_FK ON VIGFREQGRPRATMES (CDDESCOBSFILIAL ASC) 
/

ALTER TABLE VIGFREQGRPRATMES ADD 
	CONSTRAINT FKPLA01185DSCOBSFILIAL FOREIGN KEY (CDDESCOBSFILIAL) 
		REFERENCES DESCOBSFILIAL (CDDESCOBSFILIAL) ON DELETE SET NULL
/

ALTER TABLE VIGFREQOPCAGR ADD CDDESCOBSFILIAL VARCHAR2(2) NULL
/

CREATE INDEX PLA01186_FK ON VIGFREQOPCAGR (CDDESCOBSFILIAL ASC) 
/

ALTER TABLE VIGFREQOPCAGR ADD 
	CONSTRAINT FKPLA01186DESCOBSFILIAL FOREIGN KEY (CDDESCOBSFILIAL) 
		REFERENCES DESCOBSFILIAL (CDDESCOBSFILIAL) ON DELETE SET NULL
/

ALTER TABLE VIGRESTPRODGR ADD CDDESCOBSFILIAL VARCHAR2(2) NULL
/

CREATE INDEX PLA01187_FK ON VIGRESTPRODGR (CDDESCOBSFILIAL ASC) 
/

ALTER TABLE VIGRESTPRODGR ADD 
	CONSTRAINT FKPLA01187DESCOBSFILIAL FOREIGN KEY (CDDESCOBSFILIAL) 
		REFERENCES DESCOBSFILIAL (CDDESCOBSFILIAL) ON DELETE SET NULL
/

ALTER TABLE VIGFREQPRODGRPRAT ADD CDDESCOBSFILIAL VARCHAR2(2) NULL
/

CREATE INDEX PLA01188_FK ON VIGFREQPRODGRPRAT (CDDESCOBSFILIAL ASC) 
/

ALTER TABLE VIGFREQPRODGRPRAT ADD 
	CONSTRAINT FKPLA01188DESCOBSFILIAL  FOREIGN KEY (CDDESCOBSFILIAL) 
		REFERENCES DESCOBSFILIAL (CDDESCOBSFILIAL) ON DELETE SET NULL