CREATE TABLE UPDATERPRODUTOS
(
  ID              NUMBER        NOT NULL,
  NMPRODUCT 	    VARCHAR2(100) NOT NULL,
  IDUTMULTVER     VARCHAR2(1)   DEFAULT 'N' NOT NULL CONSTRAINT CKC_IDUTMULTVER_UPDPROD CHECK (IDUTMULTVER IN ('S', 'N')),
  
  NRORG           NUMBER      DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
  IDATIVO	        VARCHAR2(1) DEFAULT 'S' NOT NULL CONSTRAINT CKC_IDATIVO_UPDPROD CHECK (IDATIVO IN ('S', 'N')),
  DTINCLUSAO	    DATE NULL,
  DTULTATU	      DATE NULL,
  NRORGINCLUSAO   NUMBER DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NULL,
  NRORGULTATU     NUMBER DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NULL,
  
  CONSTRAINT PK_UPDATERPRODUTOS PRIMARY KEY (ID)
)
/
CREATE TABLE UPDATERPRODVERSAO
(
  ID              NUMBER        NOT NULL,
  UPDATERPRODID   NUMBER        NOT NULL,
  NRVERSAO        VARCHAR2(10)  NOT NULL,
  DSURL      	    VARCHAR2(100) NOT NULL,
  DSDIRETORIO	    VARCHAR2(100),
  IDDOWNLOADVER   VARCHAR2(1) DEFAULT 'P' NOT NULL,
  IDAPROVVER      VARCHAR2(1) DEFAULT 'N' NOT NULL,
  
  NRORG           NUMBER      DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
  IDATIVO	        VARCHAR2(1) DEFAULT 'S' NOT NULL CONSTRAINT CKC_IDATIVO_UPDPRODVER CHECK (IDATIVO IN ('S', 'N')),
  DTINCLUSAO	    DATE NULL,
  DTULTATU	      DATE NULL,
  NRORGINCLUSAO   NUMBER DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NULL,
  NRORGULTATU     NUMBER DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NULL,
  
  CONSTRAINT PK_UPDATERPRODVERSAO  PRIMARY KEY (ID),
  CONSTRAINT FK_UPDATERPRODVERPROD FOREIGN KEY (UPDATERPRODID) REFERENCES UPDATERPRODUTOS (ID)
)
/
CREATE SEQUENCE SEQ_UPDATERPRODVERSAO START WITH 1 MINVALUE 1 INCREMENT BY 1
/
CREATE OR REPLACE TRIGGER GERA_ID_UPDATERPRODVERSAO
BEFORE INSERT ON UPDATERPRODVERSAO FOR EACH ROW
BEGIN
  SELECT SEQ_UPDATERPRODVERSAO.NEXTVAL
    INTO :NEW.ID
    FROM DUAL;
END;
/
CREATE TABLE UPDATERPRODFILI
(
  ID              NUMBER       NOT NULL,
  UPDATERPRODID   NUMBER       NOT NULL,
  CDFILIAL        VARCHAR2(4)  NOT NULL,
  NRVERSAOATUAL	  VARCHAR2(10),
  
  NRORG           NUMBER      DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
  IDATIVO	        VARCHAR2(1) DEFAULT 'S' NOT NULL CONSTRAINT CKC_IDATIVO_UPDPRODFILI CHECK (IDATIVO IN ('S', 'N')),
  DTINCLUSAO	    DATE NULL,
  DTULTATU	      DATE NULL,
  NRORGINCLUSAO   NUMBER DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NULL,
  NRORGULTATU     NUMBER DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NULL,
  
  CONSTRAINT PK_UPDATERPRODFILI PRIMARY KEY (ID),
  CONSTRAINT FK_UPDATERPRODFILIPROD FOREIGN KEY (UPDATERPRODID) REFERENCES UPDATERPRODUTOS (ID)
)
/
CREATE SEQUENCE SEQ_UPDATERPRODFILI START WITH 1 MINVALUE 1 INCREMENT BY 1
/
CREATE OR REPLACE TRIGGER GERA_ID_UPDATERPRODFILI
BEFORE INSERT ON UPDATERPRODFILI FOR EACH ROW
BEGIN
  SELECT SEQ_UPDATERPRODFILI.NEXTVAL
    INTO :NEW.ID
    FROM DUAL;
END;
/