CREATE TABLE VERBACONSUMO (
   CDVERBA        VARCHAR2(3)  NOT NULL,
   NMVERBA        VARCHAR2(40) NOT NULL,
   NRORG          NUMBER       DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
   IDATIVO        VARCHAR2(1)  DEFAULT 'S' NOT NULL
      CONSTRAINT CKC_IDATIVO_VERBACONSUMO CHECK (IDATIVO IN ('S','N')),
   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' NULL,
   CONSTRAINT PK_VERBACONSUMO PRIMARY KEY (CDVERBA)
)
/

CREATE TABLE LOCALCONSUMO (
   CDLOCAL        VARCHAR2(3)  NOT NULL,
   NMLOCAL        VARCHAR2(40) 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' NULL,
	   CONSTRAINT CKC_IDATIVO_LOCALCONSUMO CHECK (IDATIVO IN ('S','N')),
	   CONSTRAINT PK_LOCALCONSUMO PRIMARY KEY (CDLOCAL)
)
/

CREATE TABLE VERBALOCALPROD (
   CDFILIAL       VARCHAR2(4)  NOT NULL,
   CDCAIXA        VARCHAR2(3)  NOT NULL,
   CDPRODUTO      VARCHAR2(10) NOT NULL,
   CDVERBA        VARCHAR2(3)  NOT NULL,
   CDLOCAL        VARCHAR2(3)  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' NULL,
	   CONSTRAINT CKC_IDATIVO_VERBALOCALPROD CHECK (IDATIVO IN ('S','N')),
	   CONSTRAINT PK_VERBALOCALPROD PRIMARY KEY (CDFILIAL, CDCAIXA, CDPRODUTO, CDVERBA, CDLOCAL)
)
/

CREATE INDEX VND00851_FK ON VERBALOCALPROD (CDFILIAL ASC, CDCAIXA ASC)
/

ALTER TABLE VERBALOCALPROD
   ADD CONSTRAINT FKVND00851CAIXA FOREIGN KEY (CDFILIAL, CDCAIXA)
      REFERENCES CAIXA (CDFILIAL, CDCAIXA)
/

CREATE INDEX VND00852_FK ON VERBALOCALPROD (CDPRODUTO ASC)
/

ALTER TABLE VERBALOCALPROD
   ADD CONSTRAINT FKVND00852PRODUTO FOREIGN KEY (CDPRODUTO)
      REFERENCES PRODUTO (CDPRODUTO)
/

CREATE INDEX VND00853_FK ON VERBALOCALPROD (CDVERBA ASC)
/

ALTER TABLE VERBALOCALPROD
   ADD CONSTRAINT FKVND00853VERBACONSUMO FOREIGN KEY (CDVERBA)
      REFERENCES VERBACONSUMO (CDVERBA)
/

CREATE INDEX VND00854_FK ON VERBALOCALPROD (CDLOCAL ASC)
/

ALTER TABLE VERBALOCALPROD
   ADD CONSTRAINT FKVND00854LOCALCONSUMO FOREIGN KEY (CDLOCAL)
      REFERENCES LOCALCONSUMO (CDLOCAL)
/

ALTER TABLE PARAVEND ADD CDVERBAPADRAO VARCHAR2(3) NULL
/

CREATE INDEX VND00855_FK ON PARAVEND (CDVERBAPADRAO ASC)
/
ALTER TABLE PARAVEND
   ADD CONSTRAINT FKVND00855VERBACONSUMO FOREIGN KEY (CDVERBAPADRAO)
      REFERENCES VERBACONSUMO (CDVERBA)
/

ALTER TABLE PARAVEND ADD CDLOCALPADRAO VARCHAR2(3) NULL
/

CREATE INDEX VND00856_FK ON PARAVEND (CDLOCALPADRAO ASC)
/

ALTER TABLE PARAVEND
   ADD CONSTRAINT FKVND00856LOCALCONSUMO FOREIGN KEY (CDLOCALPADRAO)
      REFERENCES LOCALCONSUMO (CDLOCAL)
/