CREATE TABLE EVENTOVENDA (
    CDEVENTO          VARCHAR2(10)  NOT NULL,
    NMEVENTO          VARCHAR2(30)  NOT NULL,
    DSEVENTO          VARCHAR2(50),
    DTINICIAL         DATE,
    DTFINAL           DATE,
    HRINICIAL         VARCHAR2(8),
    HRFINAL           VARCHAR2(8),
    NRORG             NUMBER 	      DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
    IDATIVO           VARCHAR2(1)     DEFAULT 'S'					NOT NULL,
    DTINCLUSAO        DATE            DEFAULT SYSDATE,
    DTULTATU          DATE            DEFAULT SYSDATE,
    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_EVENTOVENDA PRIMARY KEY (CDEVENTO),
		CONSTRAINT CKC_IDATIVO_EVENTOVENDA CHECK (IDATIVO IN ('S','N'))
)
/

CREATE TABLE EVENTOCAIXA (
    CDFILIAL          VARCHAR2(4)     NOT NULL,
    CDCAIXA           VARCHAR2(10)    NOT NULL,
    CDEVENTO          VARCHAR2(4)     NOT NULL,
    NRORG             NUMBER 	      DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
    IDATIVO           VARCHAR2(1)     DEFAULT 'S'					NOT NULL,
    DTINCLUSAO        DATE            DEFAULT SYSDATE,
    DTULTATU          DATE            DEFAULT SYSDATE,
    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 CKC_IDATIVO_EVENTOCAIXA CHECK (IDATIVO IN ('S','N'))
)
/
ALTER TABLE EVENTOCAIXA 
    ADD CONSTRAINT PK_EVENTOCAIXA PRIMARY KEY (CDFILIAL,CDCAIXA,CDEVENTO)
/
ALTER TABLE EVENTOCAIXA 
    ADD CONSTRAINT FKPED00456_EVENTO FOREIGN KEY(CDEVENTO) 
        REFERENCES EVENTOVENDA(CDEVENTO) 
/

CREATE INDEX PED00456_FK ON EVENTOCAIXA (CDEVENTO)
/

ALTER TABLE EVENTOCAIXA 
    ADD CONSTRAINT FKPED00457_FILIAL FOREIGN KEY(CDFILIAL) 
        REFERENCES FILIAL(CDFILIAL) 
/

CREATE INDEX PED00457_FK ON EVENTOCAIXA (CDFILIAL)
/

ALTER TABLE EVENTOCAIXA 
    ADD CONSTRAINT FKPED00458_CAIXA FOREIGN KEY(CDFILIAL, CDCAIXA) 
        REFERENCES CAIXA(CDFILIAL, CDCAIXA)
/

CREATE INDEX PED00458_FK ON EVENTOCAIXA (CDFILIAL, CDCAIXA)
/

CREATE TABLE EVENTOFILIAL (
    CDFILIAL          VARCHAR2(4)     NOT NULL,
    CDEVENTO          VARCHAR2(10)    NOT NULL,
    NRORG             NUMBER 	      DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
    IDATIVO           VARCHAR2(1)     DEFAULT 'S'					NOT NULL,
    DTINCLUSAO        DATE            DEFAULT SYSDATE,
    DTULTATU          DATE            DEFAULT SYSDATE,
    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 CKC_IDATIVO_EVENTOFILIAL CHECK (IDATIVO IN ('S','N'))
)
/
ALTER TABLE EVENTOFILIAL 
    ADD CONSTRAINT PK_EVENTOFILIAL PRIMARY KEY (CDFILIAL,CDEVENTO)
/
ALTER TABLE EVENTOFILIAL 
    ADD CONSTRAINT FKPED00459_EVENTOFILIAL FOREIGN KEY(CDEVENTO) 
        REFERENCES EVENTOVENDA(CDEVENTO) 
/

CREATE INDEX PED00459_FK ON EVENTOFILIAL (CDEVENTO)
/

ALTER TABLE EVENTOFILIAL 
    ADD CONSTRAINT FKPED00460_EVENTOCDFILIAL FOREIGN KEY(CDFILIAL) 
        REFERENCES FILIAL(CDFILIAL) 
/

CREATE INDEX PED00460_FK ON EVENTOFILIAL (CDFILIAL)
/