ALTER TABLE PARAMFILIAL ADD IDTIPOMETA VARCHAR2(1) DEFAULT 'N' NOT NULL
/

ALTER TABLE PARAMFILIAL ADD CONSTRAINT CKC_IDTIPOMETA_PARAMFILIAL CHECK (IDTIPOMETA IN ('S', 'N'))
/

CREATE TABLE METAPREVISAOHIST
  (
    CDMETAPREV     VARCHAR2(10) 	NOT NULL,   
    CDFILIAL       VARCHAR2(4)   	NOT NULL,
    IDSTATUS       VARCHAR2(1)   	DEFAULT 'M' NULL,
      CONSTRAINT CKC_IDSTATUS_METAPREVISAOHIST CHECK (IDSTATUS IN ('M', 'P', 'C')),         
    DTINICIO 		DATE 			NOT NULL, 
    DTFINAL 		DATE 			NOT NULL,
    VRPERCACRES 	FLOAT(126) 		NULL,
    CDANO 			NUMBER 			NOT	NULL,
    CDMESINICIAL 	NUMBER 			NULL,
    CDMESFINAL 		NUMBER 			NULL,
	NRORG 			NUMBER 			DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
	IDATIVO 		VARCHAR2(1) 	DEFAULT 'S' NOT NULL,
		CONSTRAINT CKC_IDATIVO_METAPREVHIST 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_METAPREVISAOHIST PRIMARY KEY (CDMETAPREV)
)
/

CREATE INDEX VND00772_FK ON METAPREVISAOHIST (CDFILIAL ASC)
/

ALTER TABLE METAPREVISAOHIST 
	ADD CONSTRAINT FKVND00772FILIAL FOREIGN KEY (CDFILIAL) 
		REFERENCES FILIAL(CDFILIAL)
/

CREATE TABLE LOGODHROTINASAUTO
(	CDLOG 			VARCHAR2(10), 
    CDROTINA 		VARCHAR2(10), 
    CDFILIAL 		VARCHAR2(4), 
    DTINICIAL 		DATE, 
    DTFINAL 		DATE, 
    IDSTATUS 		VARCHAR2(1) 	DEFAULT 'S', 
    MENSAGE 		VARCHAR2(200), 
    EXTENSAO 		VARCHAR2(10),
	NRORG 			NUMBER 			DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
	IDATIVO 		VARCHAR2(1) 	DEFAULT 'S' NOT NULL,
		CONSTRAINT CKC_IDATIVO_LOGDHROTSAUTO 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 UNIQUE INDEX PK_LOGODHROTINASAUTO ON LOGODHROTINASAUTO (CDLOG)
/

ALTER TABLE LOGODHROTINASAUTO ADD CONSTRAINT PK_LOGODHROTINASAUTO PRIMARY KEY (CDLOG)
/

ALTER TABLE LOGODHROTINASAUTO ADD CONSTRAINT CKC_IDSTATUS_LOGDHROTSAUTO CHECK (IDSTATUS IN ('S','E')) 
/

ALTER TABLE LOGODHROTINASAUTO MODIFY CDROTINA NOT NULL
/

ALTER TABLE LOGODHROTINASAUTO MODIFY CDLOG NOT NULL 
/

CREATE TABLE AGENDAODHAUTOMATIZADOR 
(	CDAGENDAODHAUT 	VARCHAR2(10), 
	CDROTINA 		VARCHAR2(10), 
	CDFILIAL 		VARCHAR2(4), 
	IDSTATUS 		VARCHAR2(1) 	DEFAULT 'S', 
	ENVIAEMAIL 		VARCHAR2(1) 	DEFAULT 'S', 
	MINUTO 			VARCHAR2(10), 
	HORA 			VARCHAR2(10), 
	DIA 			VARCHAR2(10), 
	MES 			VARCHAR2(10), 
	DIASSEMANA 		VARCHAR2(10), 
	EMAIL 			VARCHAR2(100),
	NRORG 			NUMBER 			DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
	IDATIVO 		VARCHAR2(1) 	DEFAULT 'S' NOT NULL,
		CONSTRAINT CKC_IDATIVO_AGODHAUTO 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'
)
/ 

ALTER TABLE AGENDAODHAUTOMATIZADOR ADD CONSTRAINT CKC_EMAIL_ODHAUTOMATIZADOR CHECK (ENVIAEMAIL IN ('S','N'))
/

ALTER TABLE AGENDAODHAUTOMATIZADOR ADD CONSTRAINT CKC_IDSTATUS_AGODHAUT CHECK (IDSTATUS IN ('S','N')) 
/

ALTER TABLE AGENDAODHAUTOMATIZADOR MODIFY CDROTINA NOT NULL 
/

ALTER TABLE AGENDAODHAUTOMATIZADOR MODIFY CDAGENDAODHAUT NOT NULL 
/

ALTER TABLE AGENDAODHAUTOMATIZADOR ADD CONSTRAINT PK_AGENDAODHAUTOMATIZADOR PRIMARY KEY (CDAGENDAODHAUT)