CREATE TABLE RATFISCST(
   CDCST            VARCHAR2(3)   NOT NULL ,
   CDRATEIOPADRAO   VARCHAR2(4)  NOT NULL ,
   IDENTRSAIDOP     VARCHAR2(1)  NOT NULL 
      CONSTRAINT CKC_IDENTRSAIDOP_RATFISCST CHECK ( IDENTRSAIDOP IN ( 'E', 'S' ) ) ,
   NRORG            NUMBER DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL ,
   IDATIVO          VARCHAR2(1)  DEFAULT 'S' NOT NULL ,
   DTINCLUSAO       DATE          NULL,
   DTULTATU         DATE          NULL,
   NRORGINCLUSAO    NUMBER DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NULL,
   CDOPERINCLUSAO   VARCHAR2(12)  DEFAULT '1',
   NRORGULTATU      NUMBER        DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NULL,
   CDOPERULTATU     VARCHAR2(12) DEFAULT '1',   
   CONSTRAINT PK_RATFISCST PRIMARY KEY (CDCST, CDRATEIOPADRAO, IDENTRSAIDOP)
)
/

CREATE INDEX FIS00824_FK ON RATFISCST (CDRATEIOPADRAO ASC)
/

ALTER TABLE RATFISCST 
   ADD CONSTRAINT FKFIS00824RATEIOPADRAOFIS FOREIGN KEY (CDRATEIOPADRAO)
      REFERENCES RATEIOPADRAOFIS (CDRATEIOPADRAO) ON DELETE CASCADE
/

CREATE TABLE RATFISALIQ(
   VRALIQUOTA       FLOAT                       NOT NULL ,
   CDRATEIOPADRAO   VARCHAR2(4 )                NOT NULL ,
   IDENTRSAIDOP     VARCHAR2(1 )                NOT NULL 
      CONSTRAINT CKC_IDENTRSAIDOP_RATFISALIQ CHECK ( IDENTRSAIDOP IN ( 'E', 'S' ) ) ,
   NRORG            NUMBER DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg')        NOT NULL ,
   IDATIVO          VARCHAR2(1)   DEFAULT 'S'   NOT NULL ,
   DTINCLUSAO       DATE                        NULL,
   DTULTATU         DATE                        NULL,
   NRORGINCLUSAO    NUMBER        DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NULL,
   CDOPERINCLUSAO   VARCHAR2(12)  DEFAULT '1',
   NRORGULTATU      NUMBER        DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NULL,
   CDOPERULTATU     VARCHAR2(12)  DEFAULT '1',   
   CONSTRAINT PK_RATFISALIQ PRIMARY KEY (VRALIQUOTA, CDRATEIOPADRAO, IDENTRSAIDOP)
)
/

CREATE INDEX FIS00825_FK ON RATFISALIQ(CDRATEIOPADRAO ASC)
/


ALTER TABLE RATFISALIQ
   ADD CONSTRAINT FKFIS00825RATEIOPADRAOFIS FOREIGN KEY (CDRATEIOPADRAO)
      REFERENCES RATEIOPADRAOFIS (CDRATEIOPADRAO) ON DELETE CASCADE
/      

ALTER TABLE ITMAPARECUP
   DROP CONSTRAINT FKFIS00817_CAPALOTE
/

ALTER TABLE ITDETAPUCONTR
   DROP CONSTRAINT FKFIS00819_CAPALOTE 
/

ALTER TABLE AJUSTEAPURCONTR
   DROP CONSTRAINT FKFIS00821_CAPALOTE 
/