ALTER TABLE CONFIGCARDBASE ADD IDPADRAO VARCHAR2(1) DEFAULT 'N' NOT NULL
/ 

ALTER TABLE CONFIGCARDBASE ADD CONSTRAINT CKC_IDPADRAO_CONFIGCARDBASE CHECK (IDPADRAO IN ('S', 'N'))
/

CREATE TABLE CONFGRUPTPCARDBASE (
	NRCONFGRUPTPCARDBASE 	NUMBER 			NOT NULL,
    NRCARDAPIOBASE       	NUMBER 			NOT NULL,
    CDGRTIPOPR           	VARCHAR2(2) 	NOT NULL,
	NRPORCIONAMENTO      	NUMBER 			NOT NULL,
	NRGRAMATURACARDBASE  	NUMBER 			NULL,
	IDTIPOGRAMATURA      	VARCHAR2(30) 	NULL
	   CONSTRAINT CKC_IDTIPOGRAMATURA_CONGRTPBAS CHECK (IDTIPOGRAMATURA IN ('INNATURA', 'LIMPA', 'PRONTA')),
	NRORG                	NUMBER 			DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
	IDATIVO              	VARCHAR2(1) 	DEFAULT 'S' NOT NULL
	   CONSTRAINT CKC_IDATIVO_CONFGRUPTPCARDBASE CHECK (IDATIVO IN ('S', 'N')),
	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' NULL,
	CONSTRAINT PK_CONFGRUPTPCARDBASE PRIMARY KEY (NRCONFGRUPTPCARDBASE),
	CONSTRAINT UN_CONFGRUPTPCARDBASE UNIQUE (NRCARDAPIOBASE, CDGRTIPOPR)
)
/

ALTER TABLE CONFGRUPTPCARDBASE ADD
	CONSTRAINT FKPLA01289CARDAPIOBASE FOREIGN KEY (NRCARDAPIOBASE)
		REFERENCES CARDAPIOBASE (NRCARDAPIOBASE)
/

CREATE INDEX PLA01289_FK ON CONFGRUPTPCARDBASE (NRCARDAPIOBASE)
/

ALTER TABLE CONFGRUPTPCARDBASE ADD
	CONSTRAINT FKPLA01290PORCIONAMENTO FOREIGN KEY (NRPORCIONAMENTO)
		REFERENCES PORCIONAMENTO (NRPORCIONAMENTO)
/

CREATE INDEX PLA01290_FK ON CONFGRUPTPCARDBASE (NRPORCIONAMENTO)
/

ALTER TABLE CONFGRUPTPCARDBASE ADD
	CONSTRAINT FKPLA01291GRTIPOPR FOREIGN KEY (CDGRTIPOPR)
		REFERENCES GRTIPOPR (CDGRTIPOPR)
/

CREATE INDEX PLA01291_FK ON CONFGRUPTPCARDBASE (CDGRTIPOPR)
/

ALTER TABLE CONFGRUPTPCARDBASE ADD
	CONSTRAINT FKPLA01292GRAMATURACARDBASE FOREIGN KEY (NRGRAMATURACARDBASE)
		REFERENCES GRAMATURACARDBASE (NRGRAMATURACARDBASE)
/

CREATE INDEX PLA01292_FK ON CONFGRUPTPCARDBASE (NRGRAMATURACARDBASE)
/