CREATE TABLE LOGMATPRIMA (
  NRLOGMATPRIMA NUMBER(10) NOT NULL, 
  CDPRODUTO VARCHAR2(10) NOT NULL, 
  NRORG NUMBER(10) DEFAULT 1 NOT NULL, 
  NRPLANPROD NUMBER(10) NOT NULL, 
  QTREQUERIDA DOUBLE PRECISION NOT NULL, 
  QTESTOQUE DOUBLE PRECISION NOT NULL, 
  DTVALIDACAO DATE NOT NULL, 
  DSJUSTIFICATIVA VARCHAR2(100) DEFAULT NULL NULL, 
  DSORIGEM VARCHAR2(30) DEFAULT 'PLANEJAMENTO' NOT NULL, 
  DSSTRPRODACAB VARCHAR2(2000) DEFAULT 'PLANEJAMENTO' NULL, 
  IDATIVO VARCHAR2(1) DEFAULT 'S' NOT NULL, 
  DTINCLUSAO DATE DEFAULT NULL NULL, 
  DTULTATU DATE DEFAULT NULL NULL, 
  NRORGINCLUSAO NUMBER(10) DEFAULT 1 NOT NULL, 
  CDOPERINCLUSAO VARCHAR2(12) DEFAULT '1' NOT NULL, 
  NRORGULTATU NUMBER(10) DEFAULT 1 NOT NULL, 
  CDOPERULTATU VARCHAR2(12) DEFAULT '1' NOT NULL,
  CONSTRAINT PK_LOGMATPRIMA PRIMARY KEY(NRLOGMATPRIMA, CDPRODUTO, NRORG)
)
/
ALTER TABLE LOGMATPRIMA ADD CONSTRAINT FKPLA00924PLANPRODUCAO FOREIGN KEY (NRPLANPROD, NRORG) REFERENCES PLANPRODUCAO (NRPLANPROD, NRORG)
/
ALTER TABLE LOGMATPRIMA ADD CONSTRAINT CKC_IDATIVO_LOGMATPRIMA CHECK (IDATIVO IN ('S','N'))
/
ALTER TABLE LOGMATPRIMA ADD CONSTRAINT CKC_DSORIGEM_LOGMATPRIMA CHECK (DSORIGEM IN ('PLANEJAMENTO', 'GERACAO' ))
/
CREATE INDEX  FKPLA00924PLANPRODUCAO ON LOGMATPRIMA (NRPLANPROD, NRORG)