CREATE TABLE PARAMPRATFILIAL (
	CDFILIAL            VARCHAR2(4)													NULL,
    CDFILAUXPRAT        VARCHAR2(4)													NULL,
    CDPRATO             VARCHAR2(10)												NULL,
    IDCOMPLEXIDADE      VARCHAR2(30)    DEFAULT 'BAIXA'                             NOT NULL
        CONSTRAINT CKC_IDCOMPLEXIDADE_PARAMPRFILI CHECK (IDCOMPLEXIDADE IN ('BAIXA', 'MEDIA', 'ALTA')),
    IDPREPREPARO        VARCHAR2(1)     DEFAULT 'N'                                 NOT NULL
        CONSTRAINT CKC_IDPREPREPARO_PARAMPRATFILI CHECK (IDPREPREPARO IN ('S', 'N')),
    IDCOR               VARCHAR2(30)                                                NULL,
	NRORG 				NUMBER 			DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 	NOT NULL,
	IDATIVO 			VARCHAR2(1) 	DEFAULT 'S' 								NOT NULL
		CONSTRAINT CKC_IDATIVO_PARAMPRATFILIAL 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_PARAMPRATFILIAL PRIMARY KEY (CDFILIAL, CDFILAUXPRAT, CDPRATO)    
)
/
ALTER TABLE PARAMPRATFILIAL ADD
	CONSTRAINT FKPLA01154PRATO FOREIGN KEY (CDFILAUXPRAT, CDPRATO)
		REFERENCES PRATO (CDFILAUXPRAT, CDPRATO) ON DELETE CASCADE
/
CREATE INDEX FKPLA01154PRATO ON PARAMPRATFILIAL (CDFILAUXPRAT, CDPRATO)
/
ALTER TABLE PARAMPRATFILIAL ADD
	CONSTRAINT FKPLA01155FILIAL FOREIGN KEY (CDFILIAL)
		REFERENCES FILIAL (CDFILIAL) ON DELETE CASCADE
/
CREATE INDEX FKPLA01155FILIAL ON PARAMPRATFILIAL (CDFILIAL)