-- ========================================================================
-- TABLE: TRABNECECOMP 
-- ========================================================================
CREATE TABLE ITEMSOLIRELACAF (
   NRITEMSOLIRELACAF   	INTEGER 		NOT NULL,
   CDFILSOLI         		VARCHAR2(4)	NOT NULL ,    
   CDFILLAN          		 VARCHAR2(4) 	NOT NULL ,    
   NRSOLICMP         		VARCHAR2(10)  	NOT NULL ,   
   CDPRODUTO          	VARCHAR2(10) 	NOT NULL ,   
   DTPROGENTR         	DATE 		NOT NULL , 
   CDFILDEST          		VARCHAR2(4)  	NOT NULL ,    
   CDFILLANC            	VARCHAR2(4) 	NOT NULL ,     
   NRAUTOFORN           	VARCHAR2(10) 	NOT NULL ,   
   CDMARCAAF              	VARCHAR2(5) 	NOT NULL ,    
   CDPRODUTOAF            	VARCHAR2(10) 	NOT NULL ,   
   DTPROGENTAF          	DATE 		NOT NULL ,
   DTENTRITMSOL                  	DATE,
   CDCENTITMAP    		VARCHAR2(4)  	NOT NULL,    
   NRSEQITMAP     		VARCHAR2(10) 	NOT NULL ,
   NRORG                       	NUMBER 		DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
   IDATIVO                    	VARCHAR2(1)     	DEFAULT 'S' NOT NULL
      CONSTRAINT CKC_IDATIVO_ITEMSOLIRELACAF  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_ITEMSOLIRELACAF PRIMARY KEY (NRITEMSOLIRELACAF),
	CONSTRAINT UN_ITEMSOLIRELACAF UNIQUE (CDFILSOLI, CDFILLAN, NRSOLICMP, CDPRODUTO, DTPROGENTR, CDFILDEST, CDFILLANC, NRAUTOFORN, CDMARCAAF, CDPRODUTOAF, DTPROGENTAF)
)
/

CREATE INDEX CMP00593_FK ON ITEMSOLIRELACAF (CDFILSOLI ASC, CDFILLAN ASC, NRSOLICMP ASC, CDPRODUTO ASC, DTPROGENTR ASC)
/

ALTER TABLE ITEMSOLIRELACAF ADD
	CONSTRAINT FKCMP00593ITEMSOLI  FOREIGN KEY (CDFILSOLI, CDFILLAN, NRSOLICMP, CDPRODUTO, DTPROGENTR) 
                             REFERENCES ITEMSOLI (CDFILSOLI, CDFILLAN, NRSOLICMP, CDPRODUTO, DTPROGENTR) ON DELETE CASCADE
/

CREATE INDEX CMP00594_FK ON ITEMSOLIRELACAF  (CDFILDEST ASC, CDFILLANC ASC, NRAUTOFORN ASC, CDMARCAAF ASC, CDPRODUTOAF ASC, DTPROGENTAF ASC) 
/

ALTER TABLE ITEMSOLIRELACAF ADD
	CONSTRAINT  FKCMP00594ITEMAUTF  FOREIGN KEY (CDFILDEST, CDFILLANC, NRAUTOFORN, CDMARCAAF, CDPRODUTOAF, DTPROGENTAF) 
                             REFERENCES ITEMAUTF (CDFILDEST, CDFILLANC, NRAUTOFORN, CDMARCA, CDPRODUTO, DTPROGENTAF) ON DELETE CASCADE
/

CREATE SEQUENCE SEQ_NRITEMSOLIRELACAF INCREMENT BY 1 MINVALUE 1
/

-- ========================================================================
-- TABLE: ITEMSOLIRELACAPU
-- ========================================================================
CREATE TABLE ITEMSOLIRELACAPU (
   NRITEMSOLIRELACAPU   	INTEGER 		NOT NULL,
   CDFILSOLI          		VARCHAR2(4) 	NOT NULL,    
   CDFILLAN           		VARCHAR2(4) 	NOT NULL,    
   NRSOLICMP         		VARCHAR2(10)  	NOT NULL,   
   CDPRODUTO          	VARCHAR2(10) 	NOT NULL,   
   DTPROGENTR         	DATE NOT 	NULL, 
   CDFILCENTCMP    	VARCHAR2(4)  	NOT NULL,    
   NRAPURPREC     		VARCHAR2(10) 	NOT NULL,
   NRORG                       	NUMBER 		DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
   IDATIVO                    	VARCHAR2(1)     	DEFAULT 'S' NOT NULL
      CONSTRAINT CKC_IDATIVO_ITEMSOLIRELACAPU  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_ITEMSOLIRELACAPU PRIMARY KEY (NRITEMSOLIRELACAPU),
	CONSTRAINT UN_ITEMSOLIRELACAPU UNIQUE (CDFILSOLI, CDFILLAN, NRSOLICMP, CDPRODUTO, DTPROGENTR, CDFILCENTCMP, NRAPURPREC)
 )
/

CREATE INDEX CMP00595_FK ON ITEMSOLIRELACAPU (CDFILSOLI ASC, CDFILLAN ASC, NRSOLICMP ASC, CDPRODUTO ASC, DTPROGENTR ASC) 
/

ALTER TABLE ITEMSOLIRELACAPU ADD
	CONSTRAINT FKCMP00595ITEMSOLI  FOREIGN KEY (CDFILSOLI, CDFILLAN, NRSOLICMP, CDPRODUTO, DTPROGENTR) 
                             REFERENCES ITEMSOLI (CDFILSOLI, CDFILLAN, NRSOLICMP, CDPRODUTO, DTPROGENTR) ON DELETE CASCADE
/

CREATE INDEX CMP00596_FK ON ITEMSOLIRELACAPU (CDFILCENTCMP ASC, NRAPURPREC ASC) 
/

ALTER TABLE ITEMSOLIRELACAPU ADD
	CONSTRAINT FKCMP00596APURPRECO FOREIGN KEY (CDFILCENTCMP, NRAPURPREC) 
                             REFERENCES APURPRECO (CDFILCENTCMP, NRAPURPREC) ON DELETE CASCADE
/

CREATE SEQUENCE SEQ_NRITEMSOLIRELACAPU INCREMENT BY 1 MINVALUE 1
/

-- ========================================================================
-- TABLE: LOGCORTEOL 
-- ========================================================================
ALTER TABLE LOGCORTEOL MODIFY  DTINICIAL DATE NULL    
/      

ALTER TABLE LOGCORTEOL MODIFY  DTFINAL   DATE  NULL