ALTER TABLE PARCNEGOCIO ADD IDMAUTIC NUMBER
/

ALTER TABLE CRM_CANDIDATO ADD IDMAUTIC NUMBER
/

CREATE TABLE CRM_CDETAPAS (
    NRSEQETAPA 		  NUMBER NOT NULL,
    NMETAPA 		  VARCHAR(255) NOT NULL,
    ETORDEM 		  NUMBER,
    NRETPANTE 		  NUMBER,
    NRETPPROX 		  NUMBER,
	CRM_NRORGTRAB 	  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',
		CONSTRAINT CKC_IDATIVO_CRM_CDETAPAS CHECK (IDATIVO IN ('S','N'))
)
/

    
ALTER TABLE CRM_CDETAPAS ADD CONSTRAINT PK_CRM_CDETAPAS PRIMARY KEY (NRSEQETAPA)
/
	
CREATE TABLE CRM_ETAPAPROSP (
    NRCANDIDATO 	  NUMBER NOT NULL,
    NRPARCNEGOCIO 	  NUMBER,
    NRPARCRESP 		  NUMBER,
    CDOPERRESP 		  NUMBER,
    NRSEQETAPA 		  NUMBER,
	CRM_NRORGTRAB     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',
		CONSTRAINT CKC_IDATIVO_CRM_ETAPAPROSP CHECK (IDATIVO IN ('S','N'))
)
/

ALTER TABLE CRM_ETAPAPROSP ADD CONSTRAINT PK_CRM_ETAPAPROSP PRIMARY KEY (NRCANDIDATO)
/

ALTER TABLE CRM_ETAPAPROSP 
   ADD CONSTRAINT FKCRM00095_ETAPAPROP_CANDIDATO FOREIGN KEY (NRCANDIDATO)
	   REFERENCES CRM_CANDIDATO(NRCANDIDATO)
/

CREATE INDEX CRM00095_FK ON CRM_ETAPAPROSP (NRCANDIDATO)
/

ALTER TABLE CRM_ETAPAPROSP 
   ADD CONSTRAINT FKCRM00096_ETAPAPROSP_CDETAPAS FOREIGN KEY (NRSEQETAPA)
	   REFERENCES CRM_CDETAPAS(NRSEQETAPA)
/

CREATE INDEX CRM00096_FK ON CRM_ETAPAPROSP (NRSEQETAPA)
/
	   
   
CREATE TABLE CRM_LOG_ETAPAPROSP (
    NRLOG 	  		  NUMBER NOT NULL,
    NRCANDIDATO 	  NUMBER,
    NRPARCNEGOCIO 	  NUMBER,
    NRPARCRESP 	  	  NUMBER,
    CDOPERRESP 	  	  NUMBER,
    NRSEQETAPA 	  	  NUMBER,
	CRM_NRORGTRAB 	  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',
		CONSTRAINT CKC_IDATIVO_CRM_LOG_ETAPAPROSP CHECK (IDATIVO IN ('S','N'))
)
/

ALTER TABLE CRM_LOG_ETAPAPROSP ADD CONSTRAINT PK_CRM_LOG_ETAPAPROSP PRIMARY KEY (NRLOG)
/
