CREATE TABLE PONTOPRATO (
    NRPONTOPRATO      NUMBER   NOT NULL,
    NMPONTOPRATO      VARCHAR2(40)    NOT NULL,	
    NRORG             NUMBER 	      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          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',
		CONSTRAINT CKC_IDATIVO_PONTOPRATO CHECK (IDATIVO IN ('S','N')),
		CONSTRAINT PK_PONTOPRATO PRIMARY KEY (NRPONTOPRATO)
)
/
CREATE TABLE PRATOPONTOPRATO (
    NRPONTOPRATO      NUMBER   NOT NULL,
    CDFILAUXPRAT      VARCHAR2(4)     NOT NULL,
    CDPRATO           VARCHAR2(10)    NOT NULL,	
    NRORG             NUMBER 	      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          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',
		CONSTRAINT CKC_IDATIVO_PRATOPONTOPRATO CHECK (IDATIVO IN ('S','N')),
		CONSTRAINT PK_PRATOPONTOPRATO PRIMARY KEY (NRPONTOPRATO,CDFILAUXPRAT, CDPRATO)
)
/
ALTER TABLE PRATOPONTOPRATO 
  ADD CONSTRAINT FKPLA01337_PRATOPONTOPRATO FOREIGN KEY (NRPONTOPRATO)
      REFERENCES PONTOPRATO (NRPONTOPRATO) ON DELETE CASCADE
/
CREATE INDEX PLA01337_FK ON PRATOPONTOPRATO (NRPONTOPRATO ASC)
/
ALTER TABLE PRATOPONTOPRATO 
  ADD CONSTRAINT FKPLA01338_PONTOPRATO_PRATO FOREIGN KEY (CDFILAUXPRAT, CDPRATO)
      REFERENCES PRATO (CDFILAUXPRAT, CDPRATO) ON DELETE CASCADE
/
CREATE INDEX PLA01338_FK ON PRATOPONTOPRATO (CDFILAUXPRAT ASC, CDPRATO ASC)
/