CREATE TABLE ITEMAPUCONTCTBL 
   (	CDTIPODEMO VARCHAR2(2) NOT NULL , 
	    CDITEMSTRUCTB VARCHAR2(20) NOT NULL , 
	    DSITEMSTRUCTB VARCHAR2(400), 
	    IDTIPOORIG VARCHAR2(1), 
	    IDNATUCONT VARCHAR2(2) NOT NULL , 
	    CDNUMORDEM NUMBER, 
	    CDNVCONTCTBL VARCHAR2(1) NOT NULL , 
	    IDVISUALIZA VARCHAR2(1) DEFAULT 'S' NOT NULL , 
		NRORG             NUMBER 	      DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
		IDATIVO           VARCHAR2(1)     DEFAULT 'S'					NOT NULL,
		DTINCLUSAO        DATE            DEFAULT SYSDATE,
		DTULTATU          DATE            DEFAULT SYSDATE,
		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 CKC_IDATIVO_ITEMAPUCONTCTBL CHECK (IDATIVO IN ('S','N')),
			CONSTRAINT CKC_IDVISUALIZA_ITEMAPUCONT CHECK ((IDVISUALIZA IN ('S','N'))), 
			CONSTRAINT PK_ITEMAPUCONTCTBL PRIMARY KEY (CDTIPODEMO, CDITEMSTRUCTB))
/
ALTER TABLE ITEMAPUCONTCTBL
    ADD CONSTRAINT FKCTB00326_TPDMSTR_ITMPCNTCTBL FOREIGN KEY  (CDTIPODEMO)
       REFERENCES TIPODEMOESTRU (CDTIPODEMO) ON DELETE CASCADE
/

CREATE INDEX CTB00326_FK ON ITEMAPUCONTCTBL(CDTIPODEMO ASC)
/

CREATE TABLE TIPODEMOESTRU 
(	
	CDTIPODEMO 		  VARCHAR2(2) NOT NULL , 
    NMTIPODEMO 		  VARCHAR2(30) NOT NULL , 
	IDTIPODEMO 		  VARCHAR2(1) NOT NULL ,
	NRORG             NUMBER 	      DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
    IDATIVO           VARCHAR2(1)     DEFAULT 'S'					NOT NULL,
    DTINCLUSAO        DATE            DEFAULT SYSDATE,
    DTULTATU          DATE            DEFAULT SYSDATE,
    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 CKC_IDATIVO_TIPODEMOESTRU CHECK (IDATIVO IN ('S','N')),
		CONSTRAINT CKC_IDTIPODEMO_TIPODEMO CHECK ((IDTIPODEMO IN ('D','B'))), 
		CONSTRAINT PK_TIPODEMOESTRU PRIMARY KEY (CDTIPODEMO)
)
/
