CREATE TABLE ITRATEFETCLIE (
  NRORG NUMBER(10) DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL, 
  IDATIVO VARCHAR2(1) DEFAULT 'S' NOT NULL, 
  NRORGULTATU NUMBER(10) DEFAULT 1 NULL, 
  QTEFETIVOS DOUBLE PRECISION NOT NULL, 
  CDSERVFILI VARCHAR2(5) NOT NULL, 
  CDCLIENTE VARCHAR2(21) NOT NULL, 
  DTEFETCLIE DATE NOT NULL, 
  NRITEMRATEIOEFET NUMBER(10) NOT NULL, 
  DTULTATU DATE DEFAULT NULL NULL, 
  CDOPERINCLUSAO VARCHAR2(12) DEFAULT '1' NULL, 
  CDOPERULTATU VARCHAR2(12) DEFAULT '1' NULL, 
  DTINCLUSAO DATE DEFAULT NULL NULL, 
  NRORGINCLUSAO NUMBER(10) DEFAULT 1 NULL, 
  NRITRATEFETCLIE NUMBER(10) NOT NULL, 
  CDFILIAL VARCHAR2(4) NOT NULL, 
  CDSERVPLAN VARCHAR2(5) NOT NULL,
  CONSTRAINT PK_ITRATEFETCLIE PRIMARY KEY(NRITRATEFETCLIE)
)
/
ALTER TABLE ITRATEFETCLIE ADD CONSTRAINT CKC_IDATIVO_ITRATEFETCLIE CHECK (IDATIVO IN ('S', 'N'))
/
ALTER TABLE ITRATEFETCLIE ADD CONSTRAINT UN_ITRATEFETCLIE UNIQUE (CDFILIAL, CDSERVFILI, CDCLIENTE, DTEFETCLIE, CDSERVPLAN, NRITEMRATEIOEFET)
/
ALTER TABLE ITRATEFETCLIE ADD CONSTRAINT FKPLA01001EFETCLIE FOREIGN KEY (CDFILIAL, CDSERVFILI, CDCLIENTE, DTEFETCLIE, CDSERVPLAN) REFERENCES EFETCLIE (CDFILIAL, CDSERVFILI, CDCLIENTE, DTEFETCLIE, CDSERVPLAN) ON DELETE CASCADE
/
CREATE INDEX FKPLA01001EFETCLIE ON ITRATEFETCLIE (CDFILIAL, CDSERVFILI, CDCLIENTE, DTEFETCLIE, CDSERVPLAN)
/
ALTER TABLE ITRATEFETCLIE ADD CONSTRAINT FKPLA01002ITEMRATEIOEFET FOREIGN KEY (NRITEMRATEIOEFET) REFERENCES ITEMRATEIOEFET (NRITEMRATEIOEFET)
/
CREATE INDEX FKPLA01002ITEMRATEIOEFET ON ITRATEFETCLIE (NRITEMRATEIOEFET)