CREATE TABLE EMAILADICIONAIS ( 
  IDEMAIL        NUMBER NOT NULL,
  IDORIGEM       NUMBER NOT NULL,
  CDCLIENTE      VARCHAR(21),
  CDFORNECED     VARCHAR(21),
  CDFILIAL       VARCHAR(4),
  IDTPIJURTRAN   VARCHAR2(1),
  NRINSJURTRAN   VARCHAR(20),
  DSEMAIL        VARCHAR(500),
  NRORG             NUMBER 	     	DEFAULT         SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
  IDATIVO           VARCHAR2(1)     DEFAULT 'S' NOT NULL
		CONSTRAINT CKC_IDATIVO_EMAILADICIONAIS CHECK (IDATIVO IN ('S','N')),
  DTINCLUSAO        DATE                  			NULL,
  DTULTATU          DATE                  			NULL,
  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 PK_EMAILADICIONAIS PRIMARY KEY(IDEMAIL)
)
/

CREATE INDEX FIS00826_FK ON EMAILADICIONAIS (CDCLIENTE ASC)
/

ALTER TABLE EMAILADICIONAIS
   ADD CONSTRAINT FKFIS00826_EMAILADC FOREIGN KEY(CDCLIENTE)
      REFERENCES CLIENTE(CDCLIENTE) ON DELETE CASCADE

/

CREATE INDEX FIS00827_FK ON EMAILADICIONAIS (CDFILIAL ASC)
/

ALTER TABLE EMAILADICIONAIS
    ADD CONSTRAINT FKFIS00827_EMAILADC FOREIGN KEY(CDFILIAL)
        REFERENCES FILIAL(CDFILIAL) ON DELETE CASCADE
/

CREATE INDEX FIS00828_FK ON EMAILADICIONAIS (CDFORNECED ASC)
/

ALTER TABLE EMAILADICIONAIS
    ADD CONSTRAINT FKFIS00828_EMAILADC FOREIGN KEY(CDFORNECED)
        REFERENCES FORNECEDOR(CDFORNECED) ON DELETE CASCADE
/

CREATE INDEX FIS00829_FK ON EMAILADICIONAIS (IDTPIJURTRAN ASC, NRINSJURTRAN ASC)
/

ALTER TABLE EMAILADICIONAIS
    ADD CONSTRAINT FKFIS00829_EMAILADC FOREIGN KEY(IDTPIJURTRAN, NRINSJURTRAN)
        REFERENCES TRANSPORT(IDTPIJURTRAN, NRINSJURTRAN) ON DELETE CASCADE
/