CREATE TABLE CONTABRETAUTOCDP (
	CDEMPRESA          	VARCHAR2(2)  						NOT NULL,
	IDFREQUENCIA     	VARCHAR2(1)  		DEFAULT 'D'     NOT NULL
		CONSTRAINT CKC_IDFREQUENCIA_CONTRET CHECK (IDFREQUENCIA IN ('D','S','M')),
	IDPERIODICIDADE     VARCHAR2(1) 		DEFAULT '1'     NOT NULL
		CONSTRAINT CKC_IDPERIODICIDADE_CONTRET CHECK (IDPERIODICIDADE IN ('1','2','3','4','6','8')),
		CONSTRAINT PK_CONTABRETAUTOCDP PRIMARY KEY (CDEMPRESA),
	NRORG             	NUMBER 	      		DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
    IDATIVO           	VARCHAR2(1)     	DEFAULT 'S' 	NOT NULL
		CONSTRAINT CKC_IDATIVO_CONTABRETAUTOCDP 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'
)
/

CREATE INDEX CTB00314_FK  ON CONTABRETAUTOCDP (CDEMPRESA ASC)
/

ALTER TABLE CONTABRETAUTOCDP 
    ADD CONSTRAINT FKCTB00314EMPRESA FOREIGN KEY  (CDEMPRESA)
       REFERENCES EMPRESA (CDEMPRESA)
/

ALTER TABLE FILIAL ADD IDGERCONTAUTOCDP VARCHAR2(1) DEFAULT 'N' NOT NULL 
   CONSTRAINT CKC_IDGERCONTAUTOCDP_FILIAL CHECK (IDGERCONTAUTOCDP  IN ('S','N'))
/

ALTER TABLE PARAMGERAL ADD CDHISTPADRINSU VARCHAR2(4) NULL
/

CREATE INDEX CTB00315_FK  ON PARAMGERAL (CDHISTPADRINSU ASC)
/

ALTER TABLE PARAMGERAL 
    ADD CONSTRAINT FKCTB00315HISTPADR FOREIGN KEY  (CDHISTPADRINSU )
       REFERENCES HISTPADR (CDHISTPADR)
/

ALTER TABLE PARAMGERAL ADD CDHISTPADRPRODA VARCHAR2(4) NULL
/

CREATE INDEX CTB00316_FK  ON PARAMGERAL (CDHISTPADRPRODA ASC)
/

ALTER TABLE PARAMGERAL 
    ADD CONSTRAINT FKCTB00316HISTPADR FOREIGN KEY  (CDHISTPADRPRODA)
       REFERENCES HISTPADR (CDHISTPADR)
/

ALTER TABLE PARAMGERAL ADD DSEMAILCONTAUTOCDP VARCHAR2(120) NULL
/