CREATE TABLE EXECUCAOPESQ (
  NREXECUCAOPESQ NUMBER(10) NOT NULL, 
  CDFILIAL VARCHAR2(4) NOT NULL, 
  NRLOCALPESQ NUMBER(10) DEFAULT NULL NULL, 
  NRQUESTIONARIO NUMBER(10) NOT NULL, 
  IDAPLICATIVO VARCHAR2(30) NOT NULL, 
  NRUSUARIOPESQ NUMBER(10) DEFAULT NULL NULL, 
  DTHRINICIOPESQ DATE NOT NULL, 
  DTHRFIMPESQ DATE DEFAULT NULL NULL, 
  NRORG NUMBER(10) DEFAULT 1 NOT NULL, 
  IDATIVO VARCHAR2(1) DEFAULT 'S' NOT NULL, 
  DTINCLUSAO DATE DEFAULT NULL NULL, 
  DTULTATU DATE DEFAULT NULL NULL, 
  NRORGINCLUSAO NUMBER(10) DEFAULT 1 NULL, 
  CDOPERINCLUSAO VARCHAR2(12) DEFAULT '1' NULL, 
  NRORGULTATU NUMBER(10) DEFAULT 1 NULL, 
  CDOPERULTATU VARCHAR2(12) DEFAULT '1' NULL,
  CONSTRAINT PK_EXECUCAOPESQ PRIMARY KEY(NREXECUCAOPESQ, NRORG)
)
/
ALTER TABLE EXECUCAOPESQ ADD CONSTRAINT FKMYM00005LOCALPESQ FOREIGN KEY (NRLOCALPESQ, NRORG) REFERENCES LOCALPESQ (NRLOCALPESQ, NRORG)
/
ALTER TABLE EXECUCAOPESQ ADD CONSTRAINT FKMYM00006FILIAL FOREIGN KEY (CDFILIAL, NRORG) REFERENCES FILIAL (CDFILIAL, NRORG)
/
ALTER TABLE EXECUCAOPESQ ADD CONSTRAINT FKMYM00007QUESTIONARIO FOREIGN KEY (NRQUESTIONARIO, NRORG) REFERENCES QUESTIONARIO (NRQUESTIONARIO, NRORG)
/
ALTER TABLE EXECUCAOPESQ ADD CONSTRAINT CKC_IDAPLICATIVO_EXECUCAOPESQ CHECK (IDAPLICATIVO IN ('MYMENU', 'MYQUEST'))
/
ALTER TABLE EXECUCAOPESQ ADD CONSTRAINT CKC_IDATIVO_EXECUCAOPESQ CHECK (IDATIVO IN ('S','N'))