CREATE TABLE CP_CALL (
  NRORG NUMBER(10) NOT NULL, 
  DTINCLUSAO DATE DEFAULT NULL NULL, 
  DTULTATU DATE DEFAULT NULL NULL, 
  NRORGINCLUSAO NUMBER(10) DEFAULT NULL NULL, 
  CDOPERINCLUSAO VARCHAR2(12) DEFAULT NULL NULL, 
  NRORGULTATU NUMBER(10) DEFAULT NULL NULL, 
  CDOPERULTATU VARCHAR2(12) DEFAULT NULL NULL, 
  NRCALL NUMBER(10) NOT NULL, 
  IDATIVO VARCHAR2(1) DEFAULT 'S' NOT NULL, 
  REFERENCE VARCHAR2(200) NOT NULL, 
  REPORTED_BY VARCHAR2(12) NOT NULL, 
  DESCRIPTION VARCHAR2(4000) NOT NULL, 
  TYPE VARCHAR2(1) NOT NULL, 
  CALL_RELATIONSHIP VARCHAR2(12) NOT NULL, 
  PRODUCT VARCHAR2(12) NOT NULL, 
  CLASSIFICATION VARCHAR2(12) DEFAULT NULL NULL, 
  CAUSE VARCHAR2(2) DEFAULT NULL NULL,
  CONSTRAINT PK_CP_CALL PRIMARY KEY(NRCALL, NRORG)
)
/
ALTER TABLE CP_CALL ADD CONSTRAINT CKC_IDATIVO_CP_CALL CHECK (IDATIVO IN ('S','N'))
/
CREATE TABLE CP_CALL_ATTACHMENT (
  NRORG NUMBER(10) NOT NULL, 
  DTINCLUSAO DATE DEFAULT NULL NULL, 
  DTULTATU DATE DEFAULT NULL NULL, 
  NRORGINCLUSAO NUMBER(10) DEFAULT NULL NULL, 
  CDOPERINCLUSAO VARCHAR2(12) DEFAULT NULL NULL, 
  NRORGULTATU NUMBER(10) DEFAULT NULL NULL, 
  CDOPERULTATU VARCHAR2(12) DEFAULT NULL NULL, 
  NRCALLATTACHMENT NUMBER(10) NOT NULL, 
  IDATIVO VARCHAR2(1) DEFAULT 'S' NOT NULL, 
  CALL NUMBER(10) NOT NULL, 
  LABEL VARCHAR2(1000) DEFAULT NULL NULL, 
  FILENAME VARCHAR2(1000) NOT NULL, 
  FILETYPE VARCHAR2(100) DEFAULT NULL NULL, 
  FILESIZE NUMBER(10) DEFAULT NULL NULL, 
  CALL_RELATIONSHIP_ATTACHMENT VARCHAR2(1000) DEFAULT NULL NULL,
  CONSTRAINT PK_CP_CALL_ATTACHMENT PRIMARY KEY(NRCALLATTACHMENT, NRORG)
)
/
ALTER TABLE CP_CALL_ATTACHMENT ADD CONSTRAINT CP_CALL_ATTACHMENT_CALL_FK FOREIGN KEY (CALL, NRORG) REFERENCES CP_CALL (NRCALL, NRORG)
/
ALTER TABLE CP_CALL_ATTACHMENT ADD CONSTRAINT CKC_IDATIVO_CP_CALL_ATTACHMENT CHECK (IDATIVO IN ('S','N'))
/
CREATE TABLE CP_CALL_COMMENT (
  NRORG NUMBER(10) NOT NULL, 
  DTINCLUSAO DATE DEFAULT NULL NULL, 
  DTULTATU DATE DEFAULT NULL NULL, 
  NRORGINCLUSAO NUMBER(10) DEFAULT NULL NULL, 
  CDOPERINCLUSAO VARCHAR2(12) DEFAULT NULL NULL, 
  NRORGULTATU NUMBER(10) DEFAULT NULL NULL, 
  CDOPERULTATU VARCHAR2(12) DEFAULT NULL NULL, 
  NRCALLCOMMENT NUMBER(10) NOT NULL, 
  IDATIVO VARCHAR2(1) DEFAULT 'S' NOT NULL, 
  CALL NUMBER(10) NOT NULL, 
  DESCRIPTION VARCHAR2(4000) NOT NULL,
  CONSTRAINT PK_CP_CALL_COMMENT PRIMARY KEY(NRCALLCOMMENT, NRORG)
)
/
ALTER TABLE CP_CALL_COMMENT ADD CONSTRAINT CP_CALL_COMMENT_CALL_FK FOREIGN KEY (CALL, NRORG) REFERENCES CP_CALL (NRCALL, NRORG)
/
ALTER TABLE CP_CALL_COMMENT ADD CONSTRAINT CKC_IDATIVO_CP_CALL_COMMENT CHECK (IDATIVO IN ('S','N'))
/
CREATE TABLE CP_CALL_LABEL (
  NRORG NUMBER(10) NOT NULL, 
  DTINCLUSAO DATE DEFAULT NULL NULL, 
  DTULTATU DATE DEFAULT NULL NULL, 
  NRORGINCLUSAO NUMBER(10) DEFAULT NULL NULL, 
  CDOPERINCLUSAO VARCHAR2(12) DEFAULT NULL NULL, 
  NRORGULTATU NUMBER(10) DEFAULT NULL NULL, 
  CDOPERULTATU VARCHAR2(12) DEFAULT NULL NULL, 
  NRCALLLABEL NUMBER(10) NOT NULL, 
  IDATIVO VARCHAR2(1) DEFAULT 'S' NOT NULL, 
  DESCRIPTION VARCHAR2(50) NOT NULL,
  CONSTRAINT PK_CP_CALL_LABEL PRIMARY KEY(NRCALLLABEL, NRORG)
)
/
ALTER TABLE CP_CALL_LABEL ADD CONSTRAINT CKC_IDATIVO_CP_CALL_LABEL CHECK (IDATIVO IN ('S','N'))
/
CREATE TABLE CP_CALL_LABEL_RELATION (
  NRORG NUMBER(10) NOT NULL, 
  DTINCLUSAO DATE DEFAULT NULL NULL, 
  DTULTATU DATE DEFAULT NULL NULL, 
  NRORGINCLUSAO NUMBER(10) DEFAULT NULL NULL, 
  CDOPERINCLUSAO VARCHAR2(12) DEFAULT NULL NULL, 
  NRORGULTATU NUMBER(10) DEFAULT NULL NULL, 
  CDOPERULTATU VARCHAR2(12) DEFAULT NULL NULL, 
  NRCALLLABELRELATION NUMBER(10) NOT NULL, 
  IDATIVO VARCHAR2(1) DEFAULT 'S' NOT NULL, 
  LABEL NUMBER(10) NOT NULL, 
  CALL NUMBER(10) NOT NULL,
  CONSTRAINT PK_CP_CALL_LABEL_RELATION PRIMARY KEY(NRCALLLABELRELATION, NRORG)
)
/
ALTER TABLE CP_CALL_LABEL_RELATION ADD CONSTRAINT CP_CALL_LABEL_RELAT_CALL_FK FOREIGN KEY (CALL, NRORG) REFERENCES CP_CALL (NRCALL, NRORG)
/
ALTER TABLE CP_CALL_LABEL_RELATION ADD CONSTRAINT CP_CALL_LABEL_RELAT_LABEL_FK FOREIGN KEY (LABEL, NRORG) REFERENCES CP_CALL_LABEL (NRCALLLABEL, NRORG)
/
ALTER TABLE CP_CALL_LABEL_RELATION ADD CONSTRAINT CKC_IDATIVO_CP_CALL_LABEL_REL CHECK (IDATIVO IN ('S','N'))