ALTER TABLE PARAMPEDIDO ADD IDCALCPRECFAT VARCHAR2(1) NULL  
   CONSTRAINT CKC_IDCALCPRECFAT CHECK (IDCALCPRECFAT IS NULL OR (IDCALCPRECFAT IN ('L','E')))
/

CREATE TABLE ITEMPEDRELACOL(
    NRITEMPEDRELACOL    INTEGER 			   NOT NULL,
    CDFILDEST           VARCHAR2(4)            NOT NULL,
    CDFILLANC           VARCHAR2(4)            NOT NULL,
    NRPEDEXOL           VARCHAR2(10)           NOT NULL,
    CDMARCA             VARCHAR2(5)            NOT NULL,
    CDPRODUTO           VARCHAR2(10)           NOT NULL,
    DTPROGENPEOL        DATE                   NOT NULL,
    CDFILIAL            VARCHAR2(4)            NOT NULL,
    NRPEDIDO            VARCHAR2(10)           NOT NULL,
    NRITEMPED           VARCHAR2(10)           NOT NULL,
    NRORG 				NUMBER DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
	IDATIVO 			VARCHAR2(1) DEFAULT 'S' NOT NULL,
		CONSTRAINT CKC_IDATIVO_ITEMPEDRELACOL 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_ITEMPEDRELACOL PRIMARY KEY (NRITEMPEDRELACOL),
        CONSTRAINT UN_ITEMPEDRELACOL UNIQUE (CDFILDEST, CDFILLANC, NRPEDEXOL, CDMARCA, CDPRODUTO, DTPROGENPEOL, CDFILIAL, NRPEDIDO, NRITEMPED)
    )
/
	
CREATE INDEX PED00440_FK ON ITEMPEDRELACOL (CDFILDEST ASC, CDFILLANC ASC, NRPEDEXOL ASC, CDMARCA ASC, CDPRODUTO ASC, DTPROGENPEOL ASC)
/

ALTER TABLE ITEMPEDRELACOL ADD
	CONSTRAINT FKPED00440ITEMOL  FOREIGN KEY (CDFILDEST, CDFILLANC, NRPEDEXOL, CDMARCA, CDPRODUTO, DTPROGENPEOL) 
		REFERENCES ITEMPEDEXOL (CDFILDEST, CDFILLANC, NRPEDEXOL, CDMARCA, CDPRODUTO, DTPROGENPEOL)
/

CREATE INDEX PED00441_FK ON ITEMPEDRELACOL (CDFILIAL, NRPEDIDO ASC, NRITEMPED) 
/

ALTER TABLE ITEMPEDRELACOL ADD
	CONSTRAINT  FKPED00441ITEMPED  FOREIGN KEY (CDFILIAL, NRPEDIDO, NRITEMPED) 
		REFERENCES ITEMPEDIDO (CDFILIAL, NRPEDIDO, NRITEMPED)
/

DROP SEQUENCE SEQ_NRITEMPEDRELACOL
/

CREATE SEQUENCE SEQ_NRITEMPEDRELACOL INCREMENT BY 1 MINVALUE 1