CREATE INDEX FKPLA01037TIPOPRAT ON CONFIGCARDBASE (CDTIPOPRAT)
/
ALTER TABLE CONFIGCARDBASE ADD
	CONSTRAINT FKPLA01038CARDAPIOBASE FOREIGN KEY (NRCARDAPIOBASE)
		REFERENCES CARDAPIOBASE (NRCARDAPIOBASE)
/
CREATE INDEX FKPLA01038CARDAPIOBASE ON CONFIGCARDBASE (NRCARDAPIOBASE)
/
CREATE TABLE CNFCCOMPLCARDBASE (
	NRCNFCCOMPLCARDBASE		NUMBER 														NOT NULL,
	NRCARDCOMPLCARDBASE		NUMBER														NOT NULL,
	NRCONFIGCARDBASE		NUMBER														NOT NULL,
	NRORG 					NUMBER			DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 	NOT NULL,
	IDATIVO 				VARCHAR2(1) 	DEFAULT 'S' 								NOT NULL
		CONSTRAINT CKC_IDATIVO_CNFCCOMPLCARDBASE 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' 								NULL,
	CONSTRAINT PK_CNFCCOMPLCARDBASE PRIMARY KEY (NRCNFCCOMPLCARDBASE),
	CONSTRAINT UN_CNFCCOMPLCARDBASE UNIQUE (NRCARDCOMPLCARDBASE, NRCONFIGCARDBASE)
)
/
ALTER TABLE CNFCCOMPLCARDBASE ADD
	CONSTRAINT FKPLA01039CARDCOMPLCARDBASE FOREIGN KEY (NRCARDCOMPLCARDBASE)
		REFERENCES CARDCOMPLCARDBASE (NRCARDCOMPLCARDBASE)
/
CREATE INDEX FKPLA01039CARDCOMPLCARDBASE ON CNFCCOMPLCARDBASE (NRCARDCOMPLCARDBASE)
/
ALTER TABLE CNFCCOMPLCARDBASE ADD
	CONSTRAINT FKPLA01040CONFIGCARDBASE FOREIGN KEY (NRCONFIGCARDBASE)
		REFERENCES CONFIGCARDBASE (NRCONFIGCARDBASE)
/
CREATE INDEX FKPLA01040CONFIGCARDBASE ON CNFCCOMPLCARDBASE (NRCONFIGCARDBASE)
/
CREATE TABLE DIACARDBASE (
	NRDIACARDBASE			NUMBER 														NOT NULL,
	NRCARDAPIOBASE			NUMBER														NOT NULL,
	NRSEMANA				NUMBER														NOT NULL,
	NRDIASEMANA				NUMBER														NOT NULL,
	NRORG 					NUMBER			DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 	NOT NULL,
	IDATIVO 				VARCHAR2(1) 	DEFAULT 'S' 								NOT NULL
		CONSTRAINT CKC_IDATIVO_DIACARDBASE 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' 								NULL,
	CONSTRAINT PK_DIACARDBASE PRIMARY KEY (NRDIACARDBASE),
	CONSTRAINT UN_DIACARDBASE UNIQUE (NRCARDAPIOBASE, NRSEMANA, NRDIASEMANA)
)
/
ALTER TABLE DIACARDBASE ADD
	CONSTRAINT FKPLA01041CARDAPIOBASE FOREIGN KEY (NRCARDAPIOBASE)
		REFERENCES CARDAPIOBASE (NRCARDAPIOBASE)
/
CREATE INDEX FKPLA01041CARDAPIOBASE ON DIACARDBASE (NRCARDAPIOBASE)
/
CREATE TABLE COMPCARDBASE (
	NRCOMPCARDBASE			NUMBER 														NOT NULL,
	NRCARDAPIOBASE			NUMBER														NOT NULL,
	NRDIACARDBASE			NUMBER														NOT NULL,
	NRCONFIGCARDBASE		NUMBER														NOT NULL,
	NRORG 					NUMBER			DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 	NOT NULL,
	IDATIVO 				VARCHAR2(1) 	DEFAULT 'S' 								NOT NULL
		CONSTRAINT CKC_IDATIVO_COMPCARDBASE 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' 								NULL,
	CONSTRAINT PK_COMPCARDBASE PRIMARY KEY (NRCOMPCARDBASE),
	CONSTRAINT UN_COMPCARDBASE UNIQUE (NRCARDAPIOBASE, NRDIACARDBASE, NRCONFIGCARDBASE)
)
/
ALTER TABLE COMPCARDBASE ADD
	CONSTRAINT FKPLA01042CARDAPIOBASE FOREIGN KEY (NRCARDAPIOBASE)
		REFERENCES CARDAPIOBASE (NRCARDAPIOBASE)
/
CREATE INDEX FKPLA01042CARDAPIOBASE ON COMPCARDBASE (NRCARDAPIOBASE)
/
ALTER TABLE COMPCARDBASE ADD
	CONSTRAINT FKPLA01043DIACARDBASE FOREIGN KEY (NRDIACARDBASE)
		REFERENCES DIACARDBASE (NRDIACARDBASE)
/
CREATE INDEX FKPLA01043DIACARDBASE ON COMPCARDBASE (NRDIACARDBASE)
/
ALTER TABLE COMPCARDBASE ADD
	CONSTRAINT FKPLA01044CONFIGCARDBASE FOREIGN KEY (NRCONFIGCARDBASE)
		REFERENCES CONFIGCARDBASE (NRCONFIGCARDBASE)
/
CREATE INDEX FKPLA01044CONFIGCARDBASE ON COMPCARDBASE (NRCONFIGCARDBASE)
/
CREATE TABLE PRATCOMPCARDBASE (
	NRPRATCOMPCARDBASE		NUMBER 														NOT NULL,
	NRCOMPCARDBASE			NUMBER														NOT NULL,
	CDFILAUXPRAT			VARCHAR2(4)													NOT NULL,
	CDPRATO					VARCHAR2(10)												NOT NULL,
	NRORG 					NUMBER			DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 	NOT NULL,
	IDATIVO 				VARCHAR2(1) 	DEFAULT 'S' 								NOT NULL
		CONSTRAINT CKC_IDATIVO_PRATCOMPCARDBASE 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' 								NULL,
	CONSTRAINT PK_PRATCOMPCARDBASE PRIMARY KEY (NRPRATCOMPCARDBASE),
	CONSTRAINT UN_PRATCOMPCARDBASE UNIQUE (NRCOMPCARDBASE, CDFILAUXPRAT, CDPRATO)
)
/
ALTER TABLE PRATCOMPCARDBASE ADD
	CONSTRAINT FKPLA01045COMPCARDBASE FOREIGN KEY (NRCOMPCARDBASE)
		REFERENCES COMPCARDBASE (NRCOMPCARDBASE)
/
CREATE INDEX FKPLA01045COMPCARDBASE ON PRATCOMPCARDBASE (NRCOMPCARDBASE)
/
ALTER TABLE PRATCOMPCARDBASE ADD
	CONSTRAINT FKPLA01046PRATO FOREIGN KEY (CDFILAUXPRAT, CDPRATO)
		REFERENCES PRATO (CDFILAUXPRAT, CDPRATO)
/
CREATE INDEX FKPLA01046PRATO ON PRATCOMPCARDBASE (CDFILAUXPRAT, CDPRATO)
/
CREATE TABLE REGIAOPRATCARDBASE (
	NRREGIAOPRATCARDBASE	NUMBER 														NOT NULL,
	NRPRATCOMPCARDBASE		NUMBER														NOT NULL,
	CDREGIAO				VARCHAR2(4)													NOT NULL,
	NRORG 					NUMBER			DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 	NOT NULL,
	IDATIVO 				VARCHAR2(1) 	DEFAULT 'S' 								NOT NULL
		CONSTRAINT CKC_IDATIVO_REGIAOPRATCARDBASE 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' 								NULL,
	CONSTRAINT PK_REGIAOPRATCARDBASE PRIMARY KEY (NRREGIAOPRATCARDBASE),
	CONSTRAINT UN_REGIAOPRATCARDBASE UNIQUE (NRPRATCOMPCARDBASE, CDREGIAO)
)
/
ALTER TABLE REGIAOPRATCARDBASE ADD
	CONSTRAINT FKPLA01047REGIAO FOREIGN KEY (CDREGIAO)
		REFERENCES REGIAO (CDREGIAO)
/
CREATE INDEX FKPLA01047REGIAO ON REGIAOPRATCARDBASE (CDREGIAO)
/
ALTER TABLE REGIAOPRATCARDBASE ADD
	CONSTRAINT FKPLA01048PRATCOMPCARDBASE FOREIGN KEY (NRPRATCOMPCARDBASE)
		REFERENCES PRATCOMPCARDBASE (NRPRATCOMPCARDBASE)
/
CREATE INDEX FKPLA01048PRATCOMPCARDBASE ON REGIAOPRATCARDBASE (NRPRATCOMPCARDBASE)
/
CREATE TABLE ADESAOCARDBASE (
	NRADESAOCARDBASE		NUMBER 														NOT NULL,
	NRCARDAPIOBASE			NUMBER														NOT NULL,
	CDADESAOCARDBASE		VARCHAR2(5)													NOT NULL,
	NMADESAOCARDBASE		VARCHAR2(50)												NULL,
	CDGRTIPOPR				VARCHAR2(2)													NOT NULL,
	NRDIACARDBASE			NUMBER														NULL,
	NRORG 					NUMBER			DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 	NOT NULL,
	IDATIVO 				VARCHAR2(1) 	DEFAULT 'S' 								NOT NULL
		CONSTRAINT CKC_IDATIVO_ADESAOCARDBASE 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' 								NULL,
	CONSTRAINT PK_ADESAOCARDBASE PRIMARY KEY (NRADESAOCARDBASE),
	CONSTRAINT UN_ADESAOCARDBASE UNIQUE (NRCARDAPIOBASE, CDADESAOCARDBASE)
)
/
ALTER TABLE ADESAOCARDBASE ADD
	CONSTRAINT FKPLA01049CARDAPIOBASE FOREIGN KEY (NRCARDAPIOBASE)
		REFERENCES CARDAPIOBASE (NRCARDAPIOBASE)
/
CREATE INDEX FKPLA01049CARDAPIOBASE ON ADESAOCARDBASE (NRCARDAPIOBASE)
/
ALTER TABLE ADESAOCARDBASE ADD
	CONSTRAINT FKPLA01050GRTIPOPR FOREIGN KEY (CDGRTIPOPR)
		REFERENCES GRTIPOPR (CDGRTIPOPR)
/
CREATE INDEX FKPLA01050GRTIPOPR ON ADESAOCARDBASE (CDGRTIPOPR)