CREATE TABLE ROMANEIOCARR
(
    CDFILIAL            VARCHAR2(4)         NOT NULL,
    NRLANCTONF          VARCHAR2(10)        NOT NULL,
    NRSEQITPROD         VARCHAR2(4)         NOT NULL,
    NRSEQUROMA          VARCHAR2(10)        NOT NULL,
    CDRASTREIO          VARCHAR2(30)        NOT NULL,
    DTFABRICROMA        DATE                NOT NULL,
    DTVALIDROMA         DATE                NOT NULL,
    QTPRODROMA          FLOAT               NOT NULL,
    NRLANCESTQ          VARCHAR2(10)        NULL,
    NRSEQUITEM          VARCHAR2(4)         NULL,
	NRORG 				NUMBER 				DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
	IDATIVO 			VARCHAR2(1) 		DEFAULT 'S' NOT NULL,
		CONSTRAINT CKC_IDATIVO_ROMANEIOCARR 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_ROMANEIOCARR PRIMARY KEY (CDFILIAL, NRLANCTONF, NRSEQITPROD, NRSEQUROMA)
)
/

CREATE INDEX FIS00765_FK ON ROMANEIOCARR (CDFILIAL ASC, NRLANCTONF ASC, NRSEQITPROD ASC)
/

ALTER TABLE ROMANEIOCARR
    ADD CONSTRAINT FKFIS00765ITEMPRODUTO FOREIGN KEY  (CDFILIAL, NRLANCTONF, NRSEQITPROD)
       REFERENCES ITEMPRODUTO (CDFILIAL, NRLANCTONF, NRSEQITPROD)
/

CREATE INDEX FIS00766_FK ON ROMANEIOCARR (CDFILIAL ASC, NRLANCESTQ ASC, NRSEQUITEM ASC)
/

ALTER TABLE ROMANEIOCARR
    ADD CONSTRAINT FKFIS00766ITLANCTOEST FOREIGN KEY  (CDFILIAL, NRLANCESTQ, NRSEQUITEM)
       REFERENCES ITLANCTOEST (CDFILIAL, NRLANCESTQ, NRSEQUITEM) ON DELETE CASCADE
/

ALTER TABLE PARAMFILIAL ADD VRPETOLEQTREC FLOAT
/

ALTER TABLE ITLANCTOEST ADD IDPRODDEVOL VARCHAR2(1) NULL
        CONSTRAINT CKC_IDPRODDEVOL CHECK (IDPRODDEVOL IS NULL OR (IDPRODDEVOL IN ('S','N')))
/            

ALTER TABLE PRODFILI ADD IDOBRIGROMACARR VARCHAR2(1)  NULL
        CONSTRAINT CKC_IDOBRIGROMACARR CHECK (IDOBRIGROMACARR IS NULL OR (IDOBRIGROMACARR IN ('S','N')))