CREATE TABLE FCM_OBSRESULTAUDIT (
    NROBSRESULTAUDIT        NUMBER       NOT NULL,
    NRAUDITORIA             NUMBER       NOT NULL,
	NRRELACCATTOPIC  	    NUMBER       NOT NULL,
	DSOBSERVACAO			CLOB,
    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',
			CONSTRAINT CKC_IDATIVO_FCM_OBSRESULTAUDIT CHECK (IDATIVO IN ('S','N'))
)
/
ALTER TABLE FCM_OBSRESULTAUDIT ADD CONSTRAINT PK_FCM_OBSRESULTAUDIT PRIMARY KEY (NROBSRESULTAUDIT)
/
ALTER TABLE FCM_OBSRESULTAUDIT 
  ADD CONSTRAINT FKFCM00204OBSRESULT_AUDITORIA FOREIGN KEY (NRAUDITORIA)
      REFERENCES FCM_AUDITORIA (NRAUDITORIA) 
/

CREATE INDEX FCM00204_FK ON FCM_OBSRESULTAUDIT (NRAUDITORIA)
/

ALTER TABLE FCM_OBSRESULTAUDIT 
  ADD CONSTRAINT FKFCM00205RELACATOPIC_AUDTORIA FOREIGN KEY (NRRELACCATTOPIC)
      REFERENCES FCM_RELACCATTOPIC (NRRELACCATTOPIC) 
/ 
     
CREATE INDEX FCM00205_FK ON FCM_OBSRESULTAUDIT (NRRELACCATTOPIC)
/

CREATE TABLE FCM_EPI(
    NREPI			        NUMBER        NOT NULL,
    NMEPI         		    VARCHAR2(150) 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',
		CONSTRAINT CKC_IDATIVO_FCM_EPI CHECK (IDATIVO IN ('S','N'))
)
/
ALTER TABLE FCM_EPI ADD CONSTRAINT PK_FCM_EPI PRIMARY KEY (NREPI)
/
CREATE TABLE FCM_RELCHKAGENDEPI (
    NRRELCHKAGENDEPI        NUMBER        NOT NULL,
    NREPI		    NUMBER        NOT NULL,
    NRCHECKLISTAGEND        NUMBER        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',
		CONSTRAINT CKC_IDATIVO_FCM_RELCHKAGENDEPI CHECK (IDATIVO IN ('S','N'))
)
/
ALTER TABLE FCM_RELCHKAGENDEPI ADD CONSTRAINT PK_FCM_RELCHKAGENDEPI PRIMARY KEY (NRRELCHKAGENDEPI)
/

ALTER TABLE FCM_RELCHKAGENDEPI 
  ADD CONSTRAINT FKFCM00206RELCHKAGENDEPI_EPI FOREIGN KEY (NREPI)
      REFERENCES FCM_EPI (NREPI)
/

CREATE INDEX FCM00206_FK ON FCM_RELCHKAGENDEPI (NREPI)
/
ALTER TABLE FCM_RELCHKAGENDEPI 
  ADD CONSTRAINT FKFCM00207RELCHKAGNDEPI_CHKLSTAGND FOREIGN KEY (NRCHECKLISTAGEND)
      REFERENCES FCM_CHECKLISTAGEND (NRCHECKLISTAGEND)
/

CREATE INDEX FCM00207_FK ON FCM_RELCHKAGENDEPI (NRCHECKLISTAGEND)
/

CREATE TABLE FCM_MODELOPOP (
    NRMODELOPOP		    NUMBER        NOT NULL,
    NMMODELOPOP   	    VARCHAR2(150) NOT NULL,
    DESCMODELOPOP	    CLOB,
    LINKMODELOPOP    	    VARCHAR2(2000),
    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',
		CONSTRAINT CKC_IDATIVO_FCM_MODELOPOP CHECK (IDATIVO IN ('S','N'))
)
/
ALTER TABLE FCM_MODELOPOP ADD CONSTRAINT PK_FCM_MODELOPOP PRIMARY KEY (NRMODELOPOP)
/

CREATE TABLE FCM_RELCHKAGENDMODPOP (
    NRRELCHKAGENDMODPOP     NUMBER        NOT NULL,
    NRMODELOPOP		    NUMBER        NOT NULL,
    NRCHECKLISTAGEND        NUMBER        NOT NULL,
    DSOBSERVACAO	    CLOB,
    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',
		CONSTRAINT CKC_IDATIVO_FCM_RELCKGENDMOPOP CHECK (IDATIVO IN ('S','N'))
)
/
ALTER TABLE FCM_RELCHKAGENDMODPOP ADD CONSTRAINT PK_FCM_RELCHKAGENDMODPOP PRIMARY KEY (NRRELCHKAGENDMODPOP)
/

ALTER TABLE FCM_RELCHKAGENDMODPOP 
  ADD CONSTRAINT FKFCM00208RELCHKAGENDEPI_MODPOP FOREIGN KEY (NRMODELOPOP)
      REFERENCES FCM_MODELOPOP (NRMODELOPOP)
/

CREATE INDEX FCM00208_FK ON FCM_RELCHKAGENDMODPOP (NRMODELOPOP)
/
ALTER TABLE FCM_RELCHKAGENDMODPOP 
  ADD CONSTRAINT FKFCM00209RELCHKAGNDMODPOP_CHKLSTAGND FOREIGN KEY (NRCHECKLISTAGEND)
      REFERENCES FCM_CHECKLISTAGEND (NRCHECKLISTAGEND)
/

CREATE INDEX FCM00209_FK ON FCM_RELCHKAGENDMODPOP (NRCHECKLISTAGEND)
/

CREATE TABLE FCM_ANEXOMODELOPOP (
    NRANEXOMODELOPOP        NUMBER        NOT NULL,
    NRMODELOPOP		    NUMBER        NOT NULL,
    NMARQUIVO               VARCHAR2(300), 
    DSCAMINHOARQ            VARCHAR2(500),
    DSTIPO                  VARCHAR2(150), 
    VRTAMANHO               FLOAT(126),
    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',
		CONSTRAINT CKC_IDATIVO_FCM_ANEXOMODELOPOP CHECK (IDATIVO IN ('S','N'))
)
/
ALTER TABLE FCM_ANEXOMODELOPOP ADD CONSTRAINT PK_FCM_ANEXOMODELOPOP PRIMARY KEY (NRANEXOMODELOPOP)
/

ALTER TABLE FCM_ANEXOMODELOPOP 
  ADD CONSTRAINT FKFCM00210ANEXOMOPOP_MODELPOP FOREIGN KEY (NRMODELOPOP)
      REFERENCES FCM_MODELOPOP (NRMODELOPOP)
/

CREATE INDEX FCM00210_FK ON FCM_ANEXOMODELOPOP (NRMODELOPOP)
/

CREATE TABLE FCM_EQUIPE (
    NREQUIPE		NUMBER       	NOT NULL,
    NMEQUIPE		VARCHAR2(150)	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',
		CONSTRAINT CKC_IDATIVO_FCM_EQUIPE CHECK (IDATIVO IN ('S','N'))
)
/
ALTER TABLE FCM_EQUIPE ADD CONSTRAINT PK_FCM_EQUIPE PRIMARY KEY (NREQUIPE)
/

CREATE TABLE FCM_RELACEQUIPEOPER (
    NRRELACEQUIPEOPER	NUMBER       NOT NULL,
    NREQUIPE		NUMBER       NOT NULL,
    CDOPERADOR		VARCHAR2(12) 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',
		CONSTRAINT CKC_IDATIVO_FCM_RELACQUIPEOPER CHECK (IDATIVO IN ('S','N'))
)
/
ALTER TABLE FCM_RELACEQUIPEOPER ADD CONSTRAINT PK_FCM_RELACEQUIPEOPER PRIMARY KEY (NRRELACEQUIPEOPER)
/

ALTER TABLE FCM_RELACEQUIPEOPER 
  ADD CONSTRAINT FKFCM00211EQUIPE_RELACQUIPOPER FOREIGN KEY (NREQUIPE)
      REFERENCES FCM_EQUIPE (NREQUIPE) 
/

CREATE INDEX FCM00211_FK ON FCM_RELACEQUIPEOPER (NREQUIPE)
/

ALTER TABLE FCM_RELACEQUIPEOPER 
  ADD CONSTRAINT FKFCM00212RELCEQUIPEOPE_OPRDOR FOREIGN KEY (CDOPERADOR)
      REFERENCES OPERADOR (CDOPERADOR) 
/

CREATE INDEX FCM00212_FK ON FCM_RELACEQUIPEOPER (CDOPERADOR)
/

CREATE TABLE FCM_GERCHKHISTORICO (
    NRGERCHKHISTORICO	        	NUMBER        NOT NULL,
    NRGERENCIAMENTOCHK   	       	NUMBER        NOT NULL,
    NMGERENCIAMENTOCHK                 	VARCHAR2(250) NOT NULL,
    DSGERENCIAMENTOCHK                  VARCHAR2(500),
    DTHISTGERENCIAMENTOCHK     	       	DATE NOT NULL,           
    IDTIPOHISTORICO           		CHAR(1) 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',
		CONSTRAINT CKC_IDATIVO_FCM_GERCHKHISTRICO CHECK (IDATIVO IN ('S','N'))
)
/
ALTER TABLE FCM_GERCHKHISTORICO ADD CONSTRAINT PK_FCM_GERCHKHISTORICO PRIMARY KEY (NRGERCHKHISTORICO)
/

ALTER TABLE FCM_GERCHKHISTORICO ADD CONSTRAINT CKC_IDTIPOHISTORICO_GERCHKHIST CHECK (IDTIPOHISTORICO IN ('1', '2', '3', '4', '5', '6'))
/

ALTER TABLE FCM_GERCHKHISTORICO 
  ADD CONSTRAINT FKFCM00213GERCHKHISORIC_GERCHK FOREIGN KEY (NRGERENCIAMENTOCHK)
      REFERENCES FCM_GERENCIAMENTOCHK (NRGERENCIAMENTOCHK)
/

CREATE INDEX FCM00213_FK ON FCM_GERCHKHISTORICO (NRGERENCIAMENTOCHK)
/

CREATE TABLE FCM_CHKAGENDHISTORICO (
    NRCHKAGENDHISTORICO	        	NUMBER        NOT NULL,
    NRCHECKLISTAGEND	   	       	NUMBER        NOT NULL,
    NMCHECKLISTAGEND                 	VARCHAR2(250) NOT NULL,
    DSCHKAGENDHISTORICO                  VARCHAR2(500),
    DTCHKAGENDHISTORICO     	       	DATE NOT NULL,           
    IDTIPOHISTORICO           		CHAR(1) 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',
		CONSTRAINT CKC_IDATIVO_FCM_CHKAGEHISTORIC CHECK (IDATIVO IN ('S','N'))
)
/
ALTER TABLE FCM_CHKAGENDHISTORICO ADD CONSTRAINT PK_FCM_CHKAGENDHISTORICO PRIMARY KEY (NRCHKAGENDHISTORICO)
/

ALTER TABLE FCM_CHKAGENDHISTORICO ADD CONSTRAINT CKC_IDTIPOHISTRICO_CHKAGNDHIST CHECK (IDTIPOHISTORICO IN ('1', '2', '3', '4', '5', '6', '7', '8', '9'))
/

ALTER TABLE FCM_CHKAGENDHISTORICO 
  ADD CONSTRAINT FKFCM00214CHKAGENHIS_CHKLTAGND FOREIGN KEY (NRCHECKLISTAGEND)
      REFERENCES FCM_CHECKLISTAGEND (NRCHECKLISTAGEND)
/

CREATE INDEX FCM00214_FK ON FCM_CHKAGENDHISTORICO (NRCHECKLISTAGEND)
/

ALTER TABLE FCM_PARAMGERAL ADD IDENCERRAAUTO CHAR (1) DEFAULT 'N' NOT NULL
/

ALTER TABLE FCM_PARAMGERAL ADD QTDDIASENCERRAAUTO NUMBER
/

ALTER TABLE FCM_PARAMGERAL ADD CONSTRAINT CKC_IDENCERRAAUTO CHECK (IDENCERRAAUTO IN ('S', 'N'))
/

ALTER TABLE FCM_PARAMGERAL ADD IDNAOCONFORMVIST CHAR (1)
/

ALTER TABLE FCM_PARAMGERAL ADD CONSTRAINT CKC_IDNAOCONFORMVIST CHECK (IDNAOCONFORMVIST IN ('1','2','3'))
/
