CREATE TABLE GRSITMCOLFORNOL (
  NRCOLEPRFORNOL VARCHAR2(10) NOT NULL, 
  CDFORNOL VARCHAR2(21) NOT NULL, 
  CDFORNECED VARCHAR2(21) NOT NULL, 
  CDPRODUTO VARCHAR2(10) NOT NULL, 
  CDMARCA VARCHAR2(5) NOT NULL, 
  DTINVAFORNOL DATE NOT NULL, 
  DTFIVAFORNOL DATE NOT NULL, 
  VRPRECUNIITM DOUBLE PRECISION DEFAULT NULL NULL, 
  QTDISPOFORNOL DOUBLE PRECISION DEFAULT NULL NULL, 
  NRORG NUMBER(10) DEFAULT 1 NOT NULL, 
  IDATIVO VARCHAR2(1) DEFAULT 'S' NOT NULL, 
  DTINCLUSAO DATE DEFAULT NULL NULL, 
  CDOPERINCLUSAO VARCHAR2(12) DEFAULT '1' NULL, 
  DTULTATU DATE DEFAULT NULL NULL, 
  NRORGINCLUSAO NUMBER(10) DEFAULT 1 NULL, 
  NRORGULTATU NUMBER(10) DEFAULT 1 NULL, 
  CDOPERULTATU VARCHAR2(12) DEFAULT NULL NULL,
  CONSTRAINT PK_GRSITMCOLFORNOL PRIMARY KEY(NRCOLEPRFORNOL, CDFORNOL, CDFORNECED, CDPRODUTO, CDMARCA)
)
/
ALTER TABLE GRSITMCOLFORNOL ADD CONSTRAINT FK_GRSITMCOLFORNOL_COLET FOREIGN KEY (NRCOLEPRFORNOL) REFERENCES GRSCOLEPRFORNOL (NRCOLEPRFORNOL)
/
ALTER TABLE GRSITMCOLFORNOL ADD CONSTRAINT FK_GRSITMCOLFORNOL_PARAM FOREIGN KEY (CDFORNOL, CDFORNECED) REFERENCES GRSPARAMFORNOL (CDFORNOL, CDFORNECED)
/
ALTER TABLE GRSITMCOLFORNOL ADD CONSTRAINT FK_GRSITMCOLFORNOL_PROD FOREIGN KEY (CDPRODUTO) REFERENCES PRODUTO (CDPRODUTO)
/
ALTER TABLE GRSITMCOLFORNOL ADD CONSTRAINT FK_GRSITMCOLFORNOL_MAR FOREIGN KEY (CDMARCA) REFERENCES MARCA (CDMARCA)
/
ALTER TABLE GRSITMCOLFORNOL ADD CONSTRAINT CKC_IDATIVO_GRSITMCOLFORNOL CHECK (IDATIVO IN ('S', 'N'))
/
CREATE INDEX FK_GRSITMCOLFORNOL_COLET ON GRSITMCOLFORNOL (NRCOLEPRFORNOL)
/
CREATE INDEX FK_GRSITMCOLFORNOL_PARAM ON GRSITMCOLFORNOL (CDFORNOL, CDFORNECED)
/
CREATE INDEX FK_GRSITMCOLFORNOL_PROD ON GRSITMCOLFORNOL (CDPRODUTO)
/
CREATE INDEX FK_GRSITMCOLFORNOL_MAR ON GRSITMCOLFORNOL (CDMARCA)
/
CREATE TABLE GRSAGENDAOL (
  NRAGENDAOL VARCHAR2(10) NOT NULL, 
  CDFORNECED VARCHAR2(21) NOT NULL, 
  DTINIVAGENDAOL DATE NOT NULL, 
  DTFINVAGENDAOL DATE NOT NULL, 
  CDPRODINIOL VARCHAR2(20) NOT NULL, 
  CDPRODFINOL VARCHAR2(20) NOT NULL, 
  DTAGENDAOL DATE NOT NULL, 
  CDOPERADOR VARCHAR2(12) NOT NULL, 
  IDAFPERIODO VARCHAR2(1) DEFAULT 'N' NOT NULL, 
  VRACRESCIMO DOUBLE PRECISION DEFAULT NULL NULL, 
  DSLISTAMES VARCHAR2(200) DEFAULT NULL NULL, 
  NRORG NUMBER(10) DEFAULT 1 NOT NULL, 
  IDATIVO VARCHAR2(1) DEFAULT 'S' NOT NULL, 
  DTINCLUSAO DATE DEFAULT NULL NULL, 
  CDOPERINCLUSAO VARCHAR2(12) DEFAULT '1' NULL, 
  DTULTATU DATE DEFAULT NULL NULL, 
  NRORGINCLUSAO NUMBER(10) DEFAULT 1 NULL, 
  NRORGULTATU NUMBER(10) DEFAULT 1 NULL, 
  CDOPERULTATU VARCHAR2(12) DEFAULT NULL NULL,
  CONSTRAINT PK_GRSAGENDAOL PRIMARY KEY(NRAGENDAOL, CDFORNECED)
)
/
ALTER TABLE GRSAGENDAOL ADD CONSTRAINT FK_GRSAGENDAOL_FORN FOREIGN KEY (CDFORNECED) REFERENCES FORNECEDOR (CDFORNECED)
/
ALTER TABLE GRSAGENDAOL ADD CONSTRAINT FK_GRSAGENDAOL_OP FOREIGN KEY (CDOPERADOR) REFERENCES OPERADOR (CDOPERADOR)
/
ALTER TABLE GRSAGENDAOL ADD CONSTRAINT CKC_IDATIVO_GRSAGENDAOL CHECK (IDATIVO IN ('S', 'N'))
/
ALTER TABLE GRSAGENDAOL ADD CONSTRAINT CKC_IDAFPERIODO CHECK (IDAFPERIODO in ('S','N'))
/
CREATE INDEX FK_GRSAGENDAOL_FORN ON GRSAGENDAOL (CDFORNECED)
/
CREATE INDEX FK_GRSAGENDAOL_OP ON GRSAGENDAOL (CDOPERADOR)