CREATE TABLE REALCOMESPPRATPME (
   CDREALCOMESPPRATPME VARCHAR(10) NOT NULL,
   CDFILCENTPME VARCHAR2(4) NOT NULL,
   CDFILIAL VARCHAR2(4) NOT NULL, 
   CDTIPOCARD VARCHAR2(10) NOT NULL, 
   CDTIPOPRAT VARCHAR2(2) NOT NULL, 
   CDPRATO VARCHAR2(10) NOT NULL,
   CDFILAUXPRAT VARCHAR2(4) NOT NULL,
   NRORG                      NUMBER(10) DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL, 
   IDATIVO                    VARCHAR2(1) DEFAULT 'S' NOT NULL, 
   DTINCLUSAO                 DATE DEFAULT SYSDATE, 
   DTULTATU                   DATE DEFAULT SYSDATE, 
   NRORGINCLUSAO              NUMBER(10) DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NULL, 
   CDOPERINCLUSAO             VARCHAR2(12) DEFAULT '1' NULL, 
   NRORGULTATU                NUMBER(10) DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NULL, 
   CDOPERULTATU               VARCHAR2(12) DEFAULT '1' NULL,
      CONSTRAINT CKC_IDATIVO_REALCOMESPPRATPME CHECK (IDATIVO IN ('S', 'N')),
      CONSTRAINT PK_REALCOMESPPRATPME PRIMARY KEY(CDREALCOMESPPRATPME)
)
/

CREATE INDEX PME00087_FK ON REALCOMESPPRATPME(CDFILIAL ASC)
/

ALTER TABLE REALCOMESPPRATPME ADD CONSTRAINT FKPME00087FILIAL FOREIGN KEY (CDFILIAL) REFERENCES FILIAL (CDFILIAL)
/

CREATE INDEX PME00088_FK ON REALCOMESPPRATPME(CDFILCENTPME ASC, CDTIPOCARD ASC)
/

ALTER TABLE REALCOMESPPRATPME ADD CONSTRAINT FKPME00088TIPOCARD FOREIGN KEY (CDFILCENTPME, CDTIPOCARD) REFERENCES TIPOCARD(CDFILCENTPME, CDTIPOCARD)
/

CREATE INDEX PME00089_FK ON REALCOMESPPRATPME(CDTIPOPRAT ASC)
/

ALTER TABLE REALCOMESPPRATPME ADD CONSTRAINT FKPME00089TIPOPRAT FOREIGN KEY (CDTIPOPRAT) REFERENCES TIPOPRAT (CDTIPOPRAT)
/

CREATE INDEX PME00090_FK ON REALCOMESPPRATPME(CDPRATO ASC, CDFILAUXPRAT ASC)
/

ALTER TABLE REALCOMESPPRATPME ADD CONSTRAINT FKPME00090PRATO FOREIGN KEY (CDPRATO, CDFILAUXPRAT) REFERENCES PRATO(CDPRATO, CDFILAUXPRAT)
/

CREATE TABLE COMESPPRATPME (
   CDCOMESPPRATPME VARCHAR2(10) NOT NULL,
   CDTIPOPRAT VARCHAR2(2) NOT NULL, 
   CDPRATO VARCHAR2(10) NOT NULL,
   CDFILAUXPRAT VARCHAR2(4) NOT NULL,
   QTCOMESPRAT NUMBER(10) NOT NULL,
   CDREALCOMESPPRATPME VARCHAR(10) NOT NULL,
   NRORG                      NUMBER(10) DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL, 
   IDATIVO                    VARCHAR2(1) DEFAULT 'S' NOT NULL, 
   DTINCLUSAO                 DATE DEFAULT SYSDATE, 
   DTULTATU                   DATE DEFAULT SYSDATE, 
   NRORGINCLUSAO              NUMBER(10) DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NULL, 
   CDOPERINCLUSAO             VARCHAR2(12) DEFAULT '1' NULL, 
   NRORGULTATU                NUMBER(10) DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NULL, 
   CDOPERULTATU               VARCHAR2(12) DEFAULT '1' NULL,
      CONSTRAINT CKC_IDATIVO_COMESPPRATPME CHECK (IDATIVO IN ('S', 'N')),
      CONSTRAINT PK_COMESPPRATPME PRIMARY KEY(CDCOMESPPRATPME)
)
/

CREATE INDEX PME00091_FK ON COMESPPRATPME(CDREALCOMESPPRATPME ASC)
/

ALTER TABLE COMESPPRATPME ADD CONSTRAINT FKPME00091REALCOMESPPRATPME FOREIGN KEY (CDREALCOMESPPRATPME) REFERENCES REALCOMESPPRATPME (CDREALCOMESPPRATPME)
/

CREATE INDEX PME00092_FK ON COMESPPRATPME(CDTIPOPRAT ASC)
/

ALTER TABLE COMESPPRATPME ADD CONSTRAINT FKPME00092TIPOPRAT FOREIGN KEY (CDTIPOPRAT) REFERENCES TIPOPRAT (CDTIPOPRAT)
/

CREATE INDEX PME00093_FK ON COMESPPRATPME(CDPRATO ASC, CDFILAUXPRAT ASC)
/

ALTER TABLE COMESPPRATPME ADD CONSTRAINT FKPME00093PRATO FOREIGN KEY (CDPRATO, CDFILAUXPRAT) REFERENCES PRATO(CDPRATO, CDFILAUXPRAT)
/