ALTER TABLE ADESAOCARDBASE ADD
	CONSTRAINT FFKPLA01051DIACARDBASE FOREIGN KEY (NRDIACARDBASE)
		REFERENCES DIACARDBASE (NRDIACARDBASE)
/
CREATE INDEX FFKPLA01051DIACARDBASE ON ADESAOCARDBASE (NRDIACARDBASE)
/
CREATE TABLE SEGMERADESAOCBASE (
	NRSEGMERADESAOCBASE		NUMBER 														NOT NULL,
	NRADESAOCARDBASE		NUMBER														NOT NULL,
	CDSEGMER				VARCHAR2(5)													NOT NULL,
	NRORG 					NUMBER			DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 	NOT NULL,
	IDATIVO 				VARCHAR2(1) 	DEFAULT 'S' 								NOT NULL
		CONSTRAINT CKC_IDATIVO_SEGMERADESAOCBASE 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_SEGMERADESAOCBASE PRIMARY KEY (NRSEGMERADESAOCBASE),
	CONSTRAINT UN_SEGMERADESAOCBASE UNIQUE (NRADESAOCARDBASE, CDSEGMER)
)
/
ALTER TABLE SEGMERADESAOCBASE ADD
	CONSTRAINT FKPLA01052ADESAOCARDBASE FOREIGN KEY (NRADESAOCARDBASE)
		REFERENCES ADESAOCARDBASE (NRADESAOCARDBASE)
/
CREATE INDEX FKPLA01052ADESAOCARDBASE ON SEGMERADESAOCBASE (NRADESAOCARDBASE)
/
ALTER TABLE SEGMERADESAOCBASE ADD
	CONSTRAINT FKPLA01053SEGMERCADO FOREIGN KEY (CDSEGMER)
		REFERENCES SEGMERCADO (CDSEGMER)
/
CREATE INDEX FKPLA01053SEGMERCADO ON SEGMERADESAOCBASE (CDSEGMER)
/
CREATE TABLE ATIVCLISEGMER (
	NRATIVCLISEGMER			NUMBER 														NOT NULL,
	CDSEGMER				VARCHAR2(5)													NOT NULL,
	CDATIVCLI				VARCHAR2(10)												NOT NULL,
	NRORG 					NUMBER			DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 	NOT NULL,
	IDATIVO 				VARCHAR2(1) 	DEFAULT 'S' 								NOT NULL
		CONSTRAINT CKC_IDATIVO_ATIVCLISEGMER 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_ATIVCLISEGMER PRIMARY KEY (NRATIVCLISEGMER),
	CONSTRAINT UN_ATIVCLISEGMER UNIQUE (CDSEGMER, CDATIVCLI)
)
/
ALTER TABLE ATIVCLISEGMER ADD
	CONSTRAINT FKPLA01054SEGMERCADO FOREIGN KEY (CDSEGMER)
		REFERENCES SEGMERCADO (CDSEGMER)
/
CREATE INDEX FKPLA01054SEGMERCADO ON ATIVCLISEGMER (CDSEGMER)
/
ALTER TABLE ATIVCLISEGMER ADD
	CONSTRAINT FKPLA01055ATIVCLIENTE FOREIGN KEY (CDATIVCLI)
		REFERENCES ATIVCLIENTE (CDATIVCLI)
/
CREATE INDEX FKPLA01055ATIVCLIENTE ON ATIVCLISEGMER (CDATIVCLI)
/
CREATE TABLE ATIVCLIADESAOCBASE (
	NRATIVCLIADESAOCBASE	NUMBER 														NOT NULL,
	NRADESAOCARDBASE		NUMBER														NOT NULL,
	NRATIVCLISEGMER			NUMBER														NOT NULL,
	NRORG 					NUMBER			DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 	NOT NULL,
	IDATIVO 				VARCHAR2(1) 	DEFAULT 'S' 								NOT NULL
		CONSTRAINT CKC_IDATIVO_ATIVCLIADESAOCBASE 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_ATIVCLIADESAOCBASE PRIMARY KEY (NRATIVCLIADESAOCBASE),
	CONSTRAINT UN_ATIVCLIADESAOCBASE UNIQUE (NRADESAOCARDBASE, NRATIVCLISEGMER)
)
/
ALTER TABLE ATIVCLIADESAOCBASE ADD
	CONSTRAINT FKPLA01056ADESAOCARDBASE FOREIGN KEY (NRADESAOCARDBASE)
		REFERENCES ADESAOCARDBASE (NRADESAOCARDBASE)
/
CREATE INDEX FKPLA01056ADESAOCARDBASE ON ATIVCLIADESAOCBASE (NRADESAOCARDBASE)
/
ALTER TABLE ATIVCLIADESAOCBASE ADD
	CONSTRAINT FKPLA01057ATIVCLISEGMER FOREIGN KEY (NRATIVCLISEGMER)
		REFERENCES ATIVCLISEGMER (NRATIVCLISEGMER)
/
CREATE INDEX FKPLA01057ATIVCLISEGMER ON ATIVCLIADESAOCBASE (NRATIVCLISEGMER)
/
CREATE TABLE ITEMADESAOCBASE (
	NRITEMADESAOCBASE		NUMBER 														NOT NULL,
	NRADESAOCARDBASE		NUMBER														NOT NULL,
	NRCONFIGCARDBASE		NUMBER														NOT NULL,
	NRPORCIONAMENTO			NUMBER														NOT NULL,
	VRPEADESAO				FLOAT														NOT NULL,
	NRORG 					NUMBER			DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 	NOT NULL,
	IDATIVO 				VARCHAR2(1) 	DEFAULT 'S' 								NOT NULL
		CONSTRAINT CKC_IDATIVO_ITEMADESAOCBASE 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_ITEMADESAOCBASE PRIMARY KEY (NRITEMADESAOCBASE),
	CONSTRAINT UN_ITEMADESAOCBASE UNIQUE (NRADESAOCARDBASE, NRCONFIGCARDBASE, NRPORCIONAMENTO)
)
/
ALTER TABLE ITEMADESAOCBASE ADD
	CONSTRAINT FKPLA01058ADESAOCARDBASE FOREIGN KEY (NRADESAOCARDBASE)
		REFERENCES ADESAOCARDBASE (NRADESAOCARDBASE)
/
CREATE INDEX FKPLA01058ADESAOCARDBASE ON ITEMADESAOCBASE (NRADESAOCARDBASE)
/
ALTER TABLE ITEMADESAOCBASE ADD
	CONSTRAINT FKPLA01059CONFIGCARDBASE FOREIGN KEY (NRCONFIGCARDBASE)
		REFERENCES CONFIGCARDBASE (NRCONFIGCARDBASE)
/
CREATE INDEX FKPLA01059CONFIGCARDBASE ON ITEMADESAOCBASE (NRCONFIGCARDBASE)
/
ALTER TABLE ITEMADESAOCBASE ADD
	CONSTRAINT FKPLA01060PORCIONAMENTO FOREIGN KEY (NRPORCIONAMENTO)
		REFERENCES PORCIONAMENTO (NRPORCIONAMENTO)
/
CREATE INDEX FKPLA01060PORCIONAMENTO ON ITEMADESAOCBASE (NRPORCIONAMENTO)
/
CREATE TABLE GRAMATURACARDBASE (
	NRGRAMATURACARDBASE		NUMBER 														NOT NULL,
	NRCARDAPIOBASE			NUMBER														NOT NULL,
	CDGRTIPOPR				VARCHAR2(2)													NOT NULL,
	VRGRAMATURA				FLOAT														NOT NULL,
	SGUNIDADE				VARCHAR2(10)												NOT NULL,
	IDTIPOGRAMATURA			VARCHAR2(30)												NOT NULL
		CONSTRAINT CKC_IDTIPOGRAMATURA	CHECK (IDTIPOGRAMATURA IN ('INNATURA', 'LIMPA', 'PRONTA')),
	NRTIPOPUBLICO			NUMBER 														NULL,
	NRORG 					NUMBER			DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 	NOT NULL,
	IDATIVO 				VARCHAR2(1) 	DEFAULT 'S' 								NOT NULL
		CONSTRAINT CKC_IDATIVO_GRAMATURACARDBASE 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_GRAMATURACARDBASE PRIMARY KEY (NRGRAMATURACARDBASE),
	CONSTRAINT UN_GRAMATURACARDBASE UNIQUE (NRCARDAPIOBASE, CDGRTIPOPR, VRGRAMATURA, SGUNIDADE)
)
/
ALTER TABLE GRAMATURACARDBASE ADD
	CONSTRAINT FKPLA01061CARDAPIOBASE FOREIGN KEY (NRCARDAPIOBASE)
		REFERENCES CARDAPIOBASE (NRCARDAPIOBASE)
/
CREATE INDEX FKPLA01061CARDAPIOBASE ON GRAMATURACARDBASE (NRCARDAPIOBASE)
/
ALTER TABLE GRAMATURACARDBASE ADD
	CONSTRAINT FKPLA01062GRTIPOPR FOREIGN KEY (CDGRTIPOPR)
		REFERENCES GRTIPOPR (CDGRTIPOPR)
/
CREATE INDEX FKPLA01062GRTIPOPR ON GRAMATURACARDBASE (CDGRTIPOPR)
/
ALTER TABLE GRAMATURACARDBASE ADD
	CONSTRAINT FKPLA01063UNIDMEDIDA FOREIGN KEY (SGUNIDADE)
		REFERENCES UNIDMEDIDA (SGUNIDADE)
/
CREATE INDEX FKPLA01063UNIDMEDIDA ON GRAMATURACARDBASE (SGUNIDADE)
/
ALTER TABLE GRAMATURACARDBASE ADD
	CONSTRAINT FKPLA01064TIPOPUBLICO FOREIGN KEY (NRTIPOPUBLICO)
		REFERENCES TIPOPUBLICO (NRTIPOPUBLICO)
/
CREATE INDEX FKPLA01064TIPOPUBLICO ON GRAMATURACARDBASE (NRTIPOPUBLICO)
/
CREATE TABLE ITEMGRAMCARDBASE (
	NRITEMGRAMCARDBASE		NUMBER 														NOT NULL,
	NRGRAMATURACARDBASE		NUMBER 														NOT NULL,
	CDGRUPPROD				VARCHAR2(10)												NULL,
	CDSUBGRPROD				VARCHAR2(10)												NULL,
	CDPRODUTO				VARCHAR2(10)												NULL,
	NRPORCIONAMENTO			NUMBER														NOT NULL,
	VRGRAMATURA				FLOAT														NOT NULL,
	NRORG 					NUMBER			DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 	NOT NULL,
	IDATIVO 				VARCHAR2(1) 	DEFAULT 'S' 								NOT NULL
		CONSTRAINT CKC_IDATIVO_ITEMGRAMCARDBASE 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_ITEMGRAMCARDBASE PRIMARY KEY (NRITEMGRAMCARDBASE),
	CONSTRAINT UN_ITEMGRAMCARDBASE UNIQUE (NRGRAMATURACARDBASE, CDGRUPPROD, CDSUBGRPROD, CDPRODUTO, NRPORCIONAMENTO)
)
/
ALTER TABLE ITEMGRAMCARDBASE ADD
	CONSTRAINT FKPLA01065GRAMATURACARDBASE FOREIGN KEY (NRGRAMATURACARDBASE)
		REFERENCES GRAMATURACARDBASE (NRGRAMATURACARDBASE)