CREATE TABLE GRUPOBRIGOCOR (
	CDGRPOCOR 		VARCHAR2(2) 	NOT NULL,
	CDGRUPOOBRIG 		VARCHAR2(10) 	NOT NULL,
	NMGRUPOBRIG 		VARCHAR2(200) 	NOT NULL,
	NRORG 	       		NUMBER 		DEFAULT 	SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
	IDATIVO	        	VARCHAR2(1)   	DEFAULT 'S'	NULL,
		CONSTRAINT CKC_IDATIVO_GRUPOBRIGOCOR CHECK (IDATIVO IN ('S','N')),
	DTINCLUSAO      	DATE           	NULL,
	DTULTATU        	DATE           	NULL,
	NRORGINCLUSAO   	NUMBER         	DEFAULT 1	NULL,
	CDOPERINCLUSAO  	VARCHAR2(12)   	DEFAULT '1'	NULL,
	NRORGULTATU     	NUMBER         	DEFAULT 1	NULL,
	CDOPERULTATU    	VARCHAR2(12)   	DEFAULT '1'	NULL,
		CONSTRAINT PK_GRUPOBRIGOCOR PRIMARY KEY (CDGRPOCOR, CDGRUPOOBRIG)
)
/
ALTER TABLE GRUPOBRIGOCOR 
	ADD CONSTRAINT FKVND00696GRUPOBRIGOCO_GRUPOCO FOREIGN KEY (CDGRPOCOR) 
		REFERENCES GRUPOCOR (CDGRPOCOR)
/
CREATE TABLE PRODOBRIGOCOR (
	CDGRPOCOR 		VARCHAR2(2) 	NOT NULL,
	CDGRUPOOBRIG 		VARCHAR2(10) 	NOT NULL,
	CDOCORR 		VARCHAR2(2) 	NOT NULL,
	NRORG 	       		NUMBER 		DEFAULT 	SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
	IDATIVO	        	VARCHAR2(1)   	DEFAULT 'S'	NULL,
		CONSTRAINT CKC_IDATIVO_PRODOBRIGOCOR CHECK (IDATIVO IN ('S','N')),
	DTINCLUSAO      	DATE           	NULL,
	DTULTATU        	DATE           	NULL,
	NRORGINCLUSAO   	NUMBER         	DEFAULT 1	NULL,
	CDOPERINCLUSAO  	VARCHAR2(12)   	DEFAULT '1'	NULL,
	NRORGULTATU     	NUMBER         	DEFAULT 1	NULL,
	CDOPERULTATU    	VARCHAR2(12)   	DEFAULT '1'	NULL,			
		CONSTRAINT PK_PRODOBRIGOCOR PRIMARY KEY (CDGRPOCOR, CDGRUPOOBRIG, CDOCORR)
)
/
ALTER TABLE PRODOBRIGOCOR 
	ADD CONSTRAINT FKVND00697PRODOBRIGO_GRUPOBRIG FOREIGN KEY (CDGRPOCOR, CDGRUPOOBRIG) 
		REFERENCES GRUPOBRIGOCOR (CDGRPOCOR, CDGRUPOOBRIG)
/
ALTER TABLE PRODOBRIGOCOR 
	ADD CONSTRAINT FKVND00698PRODOBRIGOCO_PRODOCO FOREIGN KEY (CDGRPOCOR, CDOCORR) 
		REFERENCES OCORRENCIA (CDGRPOCOR, CDOCORR)