CREATE TABLE FOTOPRATOBLOB(
	NRFOTOPRATOBLOB	NUMBER						NOT NULL,
	CDFILAUXPRAT	VARCHAR2(4) 				NOT NULL,
	CDPRATO 		VARCHAR2(10) 				NOT NULL,
	IDRECEITA 		VARCHAR2(1) 				NOT NULL 
		CONSTRAINT CKC_IDRECEITA_FOTOPRATOBLOB CHECK (IDRECEITA IN ('P','F','S')),
	CDFILIAL 		VARCHAR2(4) 				NULL,
	CDSERVFILI 		VARCHAR2(5) 				NULL,
	FGFOTOPRATO 	BLOB 						NULL,
	NRFOTO 			VARCHAR2(2) 				NOT NULL,
	NRORG           NUMBER         DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg')  	NOT NULL, 
	IDATIVO         VARCHAR2(1)    DEFAULT 'S' 	NOT NULL 
		CONSTRAINT CKC_IDATIVO_FOTOPRATOBLOB 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_FOTOPRATOBLOB PRIMARY KEY (NRFOTOPRATOBLOB)
)
/
ALTER TABLE FOTOPRATOBLOB ADD 
    CONSTRAINT FKMYM00030PRATO FOREIGN KEY (CDFILAUXPRAT, CDPRATO) 
        REFERENCES PRATO (CDFILAUXPRAT, CDPRATO)
/
CREATE INDEX FKMYM00030PRATO ON FOTOPRATOBLOB(CDFILAUXPRAT, CDPRATO)
/
ALTER TABLE FOTOPRATOBLOB ADD 
    CONSTRAINT FKMYM00031FILIAL FOREIGN KEY (CDFILIAL) 
        REFERENCES FILIAL (CDFILIAL)
/
CREATE INDEX FKMYM00031FILIAL ON FOTOPRATOBLOB(CDFILIAL)
/
ALTER TABLE FOTOPRATOBLOB ADD 
    CONSTRAINT FKMYM00032SERVCO FOREIGN KEY (CDFILIAL, CDSERVFILI)
        REFERENCES SERVICO (CDFILIAL, CDSERVFILI)
/
CREATE INDEX FKMYM00032SERVCO ON FOTOPRATOBLOB(CDFILIAL, CDSERVFILI)