CREATE TABLE PRODSUBGRUP
( 
   NRPRODSUBGRUP NUMBER NOT NULL,
   CDPRODUTO VARCHAR2(10) NOT NULL,
   CDGRUPPROD VARCHAR2(10) NOT NULL,
   CDSUBGRPROD VARCHAR2(10) NOT NULL,
		CONSTRAINT PK_PRODSUBGRUP PRIMARY KEY (NRPRODSUBGRUP),
		CONSTRAINT FKPLA01254PRODSUBGRUP1 FOREIGN KEY (CDGRUPPROD)
			REFERENCES GRUPPROD (CDGRUPPROD),
		CONSTRAINT FKPLA01255PRODSUBGRUP2 FOREIGN KEY (CDGRUPPROD, CDSUBGRPROD)
			REFERENCES SUBGRUPPROD (CDGRUPPROD, CDSUBGRPROD),
   NRORG             NUMBER 	     DEFAULT         SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
   IDATIVO           VARCHAR2(1)     DEFAULT 'S' NOT NULL
      CONSTRAINT CKC_IDATIVO_PRODSUBGRUP 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'		
)
/

CREATE INDEX PLA01254_FK ON PRODSUBGRUP (CDGRUPPROD ASC)
/
CREATE INDEX PLA01255_FK ON PRODSUBGRUP (CDGRUPPROD ASC, CDSUBGRPROD ASC)
/