CREATE TABLE CTRLCOMPENSACAO (
  NRCTRLCOMPENSACAO NUMBER(10) NOT NULL, 
  CDFILIAL VARCHAR2(4) NOT NULL, 
  CDFILIAPUR VARCHAR2(4) NOT NULL, 
  CDCLIENTE VARCHAR2(21) NOT NULL, 
  CDSERVFILI VARCHAR2(5) NOT NULL, 
  DTAPURACINI DATE NOT NULL, 
  DTAPURACFIM DATE NOT NULL, 
  QTEFETDIF DOUBLE PRECISION NOT NULL, 
  NRAPURACCOMP VARCHAR2(10) NOT NULL, 
  NRLANCTONF VARCHAR2(10) DEFAULT NULL NULL, 
  VRSERVICO DOUBLE PRECISION NOT NULL, 
  DTBASE DATE NOT NULL, 
  IDREINCIDENTE VARCHAR2(1) DEFAULT 'N' NOT NULL, 
  NRORG NUMBER(10) DEFAULT 1 NOT NULL, 
  IDATIVO VARCHAR2(1) DEFAULT 'S' NOT NULL, 
  DTINCLUSAO DATE DEFAULT NULL NULL, 
  DTULTATU DATE DEFAULT NULL NULL, 
  NRORGINCLUSAO NUMBER(10) DEFAULT 1 NULL, 
  CDOPERINCLUSAO VARCHAR2(12) DEFAULT '1' NULL, 
  NRORGULTATU NUMBER(10) DEFAULT 1 NULL, 
  CDOPERULTATU VARCHAR2(12) DEFAULT '1' NULL,
  CONSTRAINT PK_CTRLCOMPENSACAO PRIMARY KEY(NRCTRLCOMPENSACAO, NRORG)
)
/
ALTER TABLE CTRLCOMPENSACAO ADD CONSTRAINT FKFAI00616FILIAL FOREIGN KEY (CDFILIAL, NRORG) REFERENCES FILIAL (CDFILIAL, NRORG)
/
ALTER TABLE CTRLCOMPENSACAO ADD CONSTRAINT FKFAI00617CTRLFILIAL FOREIGN KEY (CDFILIAPUR, NRORG) REFERENCES FILIAL (CDFILIAL, NRORG)
/
ALTER TABLE CTRLCOMPENSACAO ADD CONSTRAINT FKFAI00618CLIENTE FOREIGN KEY (CDCLIENTE, NRORG) REFERENCES CLIENTE (CDCLIENTE, NRORG)
/
ALTER TABLE CTRLCOMPENSACAO ADD CONSTRAINT FKFAI00619SERVICO FOREIGN KEY (CDFILIAL, CDSERVFILI, NRORG) REFERENCES SERVICO (CDFILIAL, CDSERVFILI, NRORG)
/
ALTER TABLE CTRLCOMPENSACAO ADD CONSTRAINT FKFAI00620CTRLAPURFAT FOREIGN KEY (CDFILIAL, NRAPURACCOMP, NRORG) REFERENCES CTRLAPURFAT (CDFILIAL, NRAPURACFAT, NRORG) ON DELETE CASCADE
/
ALTER TABLE CTRLCOMPENSACAO ADD CONSTRAINT FKFAI00621NOTAFISCAL FOREIGN KEY (CDFILIAL, NRLANCTONF, NRORG) REFERENCES NOTAFISCAL (CDFILIAL, NRLANCTONF, NRORG)
/
ALTER TABLE CTRLCOMPENSACAO ADD CONSTRAINT CKC_IDATIVO_CTRLCOMPENSACAO CHECK (IDATIVO IN ('S', 'N'))
/
ALTER TABLE CTRLCOMPENSACAO ADD CONSTRAINT CKC_IDREINCIDENTE_CTRLCOMPENSA CHECK (IDREINCIDENTE IN ('S', 'N'))