CREATE TABLE FCM_MODELOAUDIT (
	NRMODELOAUDIT	  NUMBER 		  NOT NULL,
	NMMODELOAUDIT	  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'
)
/

ALTER TABLE FCM_MODELOAUDIT ADD CONSTRAINT PK_FCM_MODELOAUDIT PRIMARY KEY (NRMODELOAUDIT)
/

ALTER TABLE FCM_MODELOAUDIT ADD CONSTRAINT CKC_IDATIVO_FCM_MODELOAUDIT CHECK (IDATIVO IN ('S', 'N'))
/


CREATE TABLE FCM_CATEGORIAAUDIT (
	NRCATEGORIAAUDIT  NUMBER 		  NOT NULL,
	NMCATEGORIAAUDIT  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'
)
/

ALTER TABLE FCM_CATEGORIAAUDIT ADD CONSTRAINT PK_FCM_CATEGORIAAUDIT PRIMARY KEY (NRCATEGORIAAUDIT)
/

ALTER TABLE FCM_CATEGORIAAUDIT ADD CONSTRAINT CKC_IDATIVO_FCM_CATEGORIAAUDIT CHECK (IDATIVO IN ('S', 'N'))
/


CREATE TABLE FCM_TOPICOAUDIT (
	NRTOPICOAUDIT	  NUMBER 		  NOT NULL,
	NMTOPICOAUDIT	  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'
)
/

ALTER TABLE FCM_TOPICOAUDIT ADD CONSTRAINT PK_FCM_TOPICOAUDIT PRIMARY KEY (NRTOPICOAUDIT)
/

ALTER TABLE FCM_TOPICOAUDIT ADD CONSTRAINT CKC_IDATIVO_FCM_TOPICOAUDIT CHECK (IDATIVO IN ('S', 'N'))
/



CREATE TABLE FCM_CRITERIOAUDIT (
	NRCRITERIOAUDIT	  NUMBER 		  NOT NULL,
	NMCRITERIOAUDIT	  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'
)
/

ALTER TABLE FCM_CRITERIOAUDIT ADD CONSTRAINT PK_FCM_CRITERIOAUDIT PRIMARY KEY (NRCRITERIOAUDIT)
/

ALTER TABLE FCM_CRITERIOAUDIT ADD CONSTRAINT CKC_IDATIVO_FCM_CRITERIOAUDIT CHECK (IDATIVO IN ('S', 'N'))
/


CREATE TABLE FCM_AUDITORIA (
	NRAUDITORIA	    	NUMBER  	    NOT NULL,
	NMAUDITORIA	    	VARCHAR2(250)   NOT NULL,
	NRLOCALCLIENTE      NUMBER  	    NOT NULL,
	NRMODELOAUDIT       NUMBER  	    NOT NULL,
	NRSEQCONTRATO       NUMBER,
	CDOPERADOR	    	VARCHAR2(12),
	IDSITUACAOAUDIT     VARCHAR2(1)	    DEFAULT '1' NOT NULL,
	DTHORAAUDIT         DATE,
	IDOBRIGAOBSERVACAO	VARCHAR2(1),
  	IDTIPORECORRENCIA	VARCHAR2(2),
	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'
)
/

ALTER TABLE FCM_AUDITORIA ADD CONSTRAINT PK_FCM_AUDITORIA PRIMARY KEY (NRAUDITORIA)
/

ALTER TABLE FCM_AUDITORIA 
  ADD CONSTRAINT FKFCM00174_LOCALCLI_AUDITORIA FOREIGN KEY (NRLOCALCLIENTE)
      REFERENCES FCM_LOCALCLI (NRLOCALCLIENTE)
/

CREATE INDEX FCM00174_FK ON FCM_AUDITORIA (NRLOCALCLIENTE)
/

ALTER TABLE FCM_AUDITORIA 
  ADD CONSTRAINT FKFCM00175_MODELO_AUDIT FOREIGN KEY (NRMODELOAUDIT)
      REFERENCES FCM_MODELOAUDIT (NRMODELOAUDIT)
/

CREATE INDEX FCM00175_FK ON FCM_AUDITORIA (NRMODELOAUDIT)
/

ALTER TABLE FCM_AUDITORIA 
  ADD CONSTRAINT FKFCM00176_OPERA_FCM_AUDIT FOREIGN KEY (CDOPERADOR)
      REFERENCES OPERADOR (CDOPERADOR)
/ 

CREATE INDEX FCM00176_FK ON FCM_AUDITORIA (CDOPERADOR)
/   
  
ALTER TABLE FCM_AUDITORIA 
  ADD CONSTRAINT FKFCM00177_FCT_CONT_FCM_AUDIT FOREIGN KEY (NRSEQCONTRATO)
      REFERENCES FCT_CONTRATO (NRSEQCONTRATO)
/

CREATE INDEX FCM00177_FK ON FCM_AUDITORIA (NRSEQCONTRATO)
/

ALTER TABLE FCM_AUDITORIA ADD CONSTRAINT CKC_IDSITUACAOAUDIT CHECK (IDSITUACAOAUDIT IN ('1', '2', '3'))
/


ALTER TABLE FCM_AUDITORIA ADD CONSTRAINT CKC_IDATIVO_FCM_AUDITORIA CHECK (IDATIVO IN ('S', 'N'))
/


CREATE TABLE FCM_RESULTADOAUDIT (
	NRRESULTADOAUDIT  NUMBER 	      NOT NULL,
	NRAUDITORIA	      NUMBER  	      NOT NULL,
	NRMODELOAUDIT     NUMBER  	      NOT NULL,
	NRTOPICOAUDIT	  NUMBER  		  NOT NULL,
	NRCRITERIOAUDIT	  NUMBER,
	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'
)
/

ALTER TABLE FCM_RESULTADOAUDIT ADD CONSTRAINT PK_FCM_RESULTADOAUDIT PRIMARY KEY (NRRESULTADOAUDIT)
/

ALTER TABLE FCM_RESULTADOAUDIT 
  ADD CONSTRAINT FKFCM00178_FCM_AUDIT_RESUT FOREIGN KEY (NRAUDITORIA)
      REFERENCES FCM_AUDITORIA (NRAUDITORIA)
/

CREATE INDEX FCM00178_FK ON FCM_RESULTADOAUDIT (NRAUDITORIA)
/

ALTER TABLE FCM_RESULTADOAUDIT 
  ADD CONSTRAINT FKFCM00179_FCM_MODEL_RESULT FOREIGN KEY (NRMODELOAUDIT)
      REFERENCES FCM_MODELOAUDIT (NRMODELOAUDIT)
/

CREATE INDEX FCM00179_FK ON FCM_RESULTADOAUDIT (NRMODELOAUDIT)
/

ALTER TABLE FCM_RESULTADOAUDIT 
  ADD CONSTRAINT FKFCM00180_TOPIC_RESUIT FOREIGN KEY (NRTOPICOAUDIT)
      REFERENCES FCM_TOPICOAUDIT (NRTOPICOAUDIT)
/ 
 
CREATE INDEX FCM00180_FK ON FCM_RESULTADOAUDIT (NRTOPICOAUDIT)
/ 
  
ALTER TABLE FCM_RESULTADOAUDIT 
  ADD CONSTRAINT FKFCM00181_CRITERI_RESULIT FOREIGN KEY (NRCRITERIOAUDIT)
      REFERENCES FCM_CRITERIOAUDIT (NRCRITERIOAUDIT)
/

CREATE INDEX FCM00181_FK ON FCM_RESULTADOAUDIT (NRCRITERIOAUDIT)
/

ALTER TABLE FCM_RESULTADOAUDIT ADD CONSTRAINT CKC_IDATIVO_FCM_RESULTADOAUDIT CHECK (IDATIVO IN ('S', 'N'))
/


 CREATE TABLE FCM_FOTORESULTAUDIT (	
 	NRFOTORESULTAUDIT	NUMBER 		    NOT NULL, 
	NRRESULTADOAUDIT	NUMBER          NOT NULL,
	NRMODELOAUDIT		NUMBER 			NOT NULL,
	DSFOTOTAREFAAGEND 	VARCHAR2(1000)  NOT NULL, 
	DSTYPE		 	  	VARCHAR2(100), 
	NRSIZE 			    NUMBER,
	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'
)
/

ALTER TABLE FCM_FOTORESULTAUDIT ADD CONSTRAINT PK_FCM_FOTORESULTAUDIT PRIMARY KEY (NRFOTORESULTAUDIT)
/

ALTER TABLE FCM_FOTORESULTAUDIT 
  ADD CONSTRAINT FKFCM00182_RESULT_FTREDIT FOREIGN KEY (NRRESULTADOAUDIT)
      REFERENCES FCM_RESULTADOAUDIT (NRRESULTADOAUDIT)
/

CREATE INDEX FCM00182_FK ON FCM_FOTORESULTAUDIT (NRRESULTADOAUDIT)
/

ALTER TABLE FCM_FOTORESULTAUDIT 
  ADD CONSTRAINT FKFCM00183_MODELO_FTREDIT FOREIGN KEY (NRMODELOAUDIT)
      REFERENCES FCM_MODELOAUDIT (NRMODELOAUDIT)
/

CREATE INDEX FCM00183_FK ON FCM_FOTORESULTAUDIT (NRMODELOAUDIT)
/ 
     
ALTER TABLE FCM_FOTORESULTAUDIT ADD CONSTRAINT CKC_IDATIVO_FCM_FTRESULTAUDIT CHECK (IDATIVO IN ('S', 'N'))
/


CREATE TABLE FCM_RELACCATTOPIC (
	NRRELACCATTOPIC   NUMBER 		  NOT NULL,
	NRCATEGORIAAUDIT  NUMBER 		  NOT NULL,
	NRTOPICOAUDIT	  NUMBER 		  NOT NULL,
	NRMODELOAUDIT     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'
)
/

ALTER TABLE FCM_RELACCATTOPIC ADD CONSTRAINT PK_FCM_RELACCATTOPIC PRIMARY KEY (NRRELACCATTOPIC)
/

ALTER TABLE FCM_RELACCATTOPIC ADD CONSTRAINT CKC_IDATIVO_FCM_RELACCATTOPIC CHECK (IDATIVO IN ('S', 'N'))
/

ALTER TABLE FCM_RELACCATTOPIC 
  ADD CONSTRAINT FKFCM00184_CATEGORIA_RELCAT FOREIGN KEY (NRCATEGORIAAUDIT)
      REFERENCES FCM_CATEGORIAAUDIT (NRCATEGORIAAUDIT)
/

CREATE INDEX FCM00184_FK ON FCM_RELACCATTOPIC (NRCATEGORIAAUDIT)
/ 
     
ALTER TABLE FCM_RELACCATTOPIC 
  ADD CONSTRAINT FKFCM00185_TOPICO_RELCAT FOREIGN KEY (NRTOPICOAUDIT)
      REFERENCES FCM_TOPICOAUDIT (NRTOPICOAUDIT)
/ 
 
CREATE INDEX FCM00185_FK ON FCM_RELACCATTOPIC (NRTOPICOAUDIT)
/ 


CREATE TABLE FCM_RELACCATEGCRIT (
	NRRELACMODCRIT  	NUMBER NOT NULL,
	NRCATEGORIAAUDIT	NUMBER NOT NULL,
	NRCRITERIOAUDIT		NUMBER NOT NULL,
	NRMODELOAUDIT       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'
)
/

ALTER TABLE FCM_RELACCATEGCRIT ADD CONSTRAINT PK_FCM_RELACCATEGCRIT PRIMARY KEY (NRRELACMODCRIT)
/

ALTER TABLE FCM_RELACCATEGCRIT ADD CONSTRAINT CKC_IDATIVO_FCM_RELACCATEGCRIT CHECK (IDATIVO IN ('S', 'N'))
/

ALTER TABLE FCM_RELACCATEGCRIT 
  ADD CONSTRAINT FKFCM00186_CATEGORIA_RELCIT FOREIGN KEY (NRCATEGORIAAUDIT)
      REFERENCES FCM_CATEGORIAAUDIT (NRCATEGORIAAUDIT)
/
 
CREATE INDEX FCM00186_FK ON FCM_RELACCATEGCRIT (NRCATEGORIAAUDIT)
/ 
    
ALTER TABLE FCM_RELACCATEGCRIT 
  ADD CONSTRAINT FKFCM00187_CRITERIO_RELCATEG FOREIGN KEY (NRCRITERIOAUDIT)
      REFERENCES FCM_CRITERIOAUDIT (NRCRITERIOAUDIT)
/

CREATE INDEX FCM00187_FK ON FCM_RELACCATEGCRIT (NRCRITERIOAUDIT)
/


CREATE TABLE FCM_RELACMODCATEG (
	NRRELACMODCATEG  	NUMBER 		    NOT NULL,
	NRMODELOAUDIT		NUMBER 	        NOT NULL,
	NRCATEGORIAAUDIT	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'
)
/

ALTER TABLE FCM_RELACMODCATEG ADD CONSTRAINT PK_FCM_RELACMODCATEG PRIMARY KEY (NRRELACMODCATEG)
/

ALTER TABLE FCM_RELACMODCATEG ADD CONSTRAINT CKC_IDATIVO_FCM_RELACMODCATEG CHECK (IDATIVO IN ('S', 'N'))
/

ALTER TABLE FCM_RELACMODCATEG 
  ADD CONSTRAINT FKFCM00188_MODEL_RELACATEG FOREIGN KEY (NRMODELOAUDIT)
      REFERENCES FCM_MODELOAUDIT (NRMODELOAUDIT)
/  
  
CREATE INDEX FCM00188_FK ON FCM_RELACMODCATEG (NRMODELOAUDIT)
/ 

ALTER TABLE FCM_RELACMODCATEG 
  ADD CONSTRAINT FKFCM00189_CAT_RELACMODCATE FOREIGN KEY (NRCATEGORIAAUDIT)
      REFERENCES FCM_CATEGORIAAUDIT (NRCATEGORIAAUDIT)
/

CREATE INDEX FCM00189_FK ON FCM_RELACMODCATEG (NRCATEGORIAAUDIT)
/