CREATE TABLE ENDERAUTOFORNE (
   NRENDERAUTOFORNE    INTEGER  NOT NULL,
   CDFILIAL             VARCHAR2(4) NOT NULL,
   CONSTRAINT FK_ENDEAF_FILIAL  FOREIGN KEY (CDFILIAL) 
                             REFERENCES FILIAL (CDFILIAL) ON DELETE CASCADE,
   IDENDENTREGAAF       VARCHAR2(2)  DEFAULT 'EA' NULL
   CONSTRAINT CKC_ENDAF_IDENDENTREGAAF CHECK (IDENDENTREGAAF IS NULL OR (IDENDENTREGAAF IN ('EA', '01', '02'))),
   IDENDFATURAMENTOAF       VARCHAR2(2)   DEFAULT 'EA' NULL
   CONSTRAINT CKC_ENDAF_IDENDFATURAMENTOAF CHECK (IDENDFATURAMENTOAF IS NULL OR (IDENDFATURAMENTOAF IN ('EA', 'NN', 'EP', 'EE', 'CL', 'IE'))),
   IDREPRESENTAFATAF       VARCHAR2(2)    DEFAULT 'EA' NULL
   CONSTRAINT CKC_ENDAF_IDREPRESENTAFATAF CHECK (IDREPRESENTAFATAF IS NULL OR (IDREPRESENTAFATAF IN ('EA', 'NN', 'NF', 'RF', 'EP', 'CL', 'EE'))),   
   IDENDCOBRANCAAF       VARCHAR2(2) DEFAULT 'EA' NULL
   CONSTRAINT CKC_ENDAF_IDENDCOBRANCAAF CHECK (IDENDCOBRANCAAF IS NULL OR (IDENDCOBRANCAAF IN ('EA', 'NN', 'EP', 'EC', 'EE', 'CL', 'IE'))),
   IDREPRESENTACOBRAAF VARCHAR2(2)  DEFAULT 'EA' NULL
   CONSTRAINT CKC_ENDAF_IDREPRESENTACOBRAAF CHECK (IDREPRESENTACOBRAAF IS NULL OR (IDREPRESENTACOBRAAF IN ('EA', 'NN', 'NF', 'RF', 'EP', 'CL', 'EE'))),
   NRORG                        NUMBER  DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
   IDATIVO                     VARCHAR2(1)      DEFAULT 'S' NOT NULL
      CONSTRAINT CKC_IDATIVO_ENDERAUTOFORNE  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_ENDERAUTOFORNE PRIMARY KEY (NRENDERAUTOFORNE),
 CONSTRAINT UN_ENDERAUTOFORNE UNIQUE (CDFILIAL)
)
/