ALTER TABLE DEDUCAOROP ADD CDTPCTPAGAR VARCHAR2(6) NULL
/
ALTER TABLE DEDUCAOROP ADD
	CONSTRAINT FKGOP00725TIPOCTPAGAR FOREIGN KEY (CDTPCTPAGAR)
		REFERENCES TIPOCTPAGAR (CDTPCTPAGAR)
/
CREATE INDEX FKGOP00725TIPOCTPAGAR ON DEDUCAOROP (CDTPCTPAGAR)
/
CREATE TABLE CRM_PARAMSERVICE
(
    NRPARAMSERVICE      	NUMBER                 		NOT NULL,
    NRPERFILACESSO      	NUMBER                 		NULL    ,
    NRTPARVPROD         	VARCHAR2(100)          	NULL    ,
    NMEQUIPEATENDE      	VARCHAR2(100)          	NULL    ,
    NRDIASENCERRAMENTO  	NUMBER                		NULL    ,
    IDRESUEVOL          	VARCHAR2(1)            	DEFAULT 'N' NOT NULL
	CONSTRAINT CKC_524IDRESUEVOL CHECK (IDRESUEVOL IN ('S','N')),
    NRORG               		NUMBER                 		DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
    DTINCLUSAO          	DATE                   		DEFAULT SYSDATE NOT NULL,
    DTULTATU            	DATE                   		NULL    ,
    NRORGINCLUSAO       	NUMBER                 		DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
    CDOPERINCLUSAO      	VARCHAR2(12)           	DEFAULT '1' NOT NULL,
    NRORGULTATU         	NUMBER                 		DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
    CDOPERULTATU        	VARCHAR2(12)           	DEFAULT '1' NOT NULL,
    IDATIVO             		VARCHAR2(1)            	DEFAULT 'S' NOT NULL
	CONSTRAINT CKCIDATIVOCRM_PARAMSVC CHECK (IDATIVO IN ('S','N')),
	CONSTRAINT CRM_PARAMSERVICE_PK PRIMARY KEY (NRPARAMSERVICE)
)
/
CREATE INDEX FKCRM_0122_CRM_PARAMSERVICE ON CRM_PARAMSERVICE (NRPERFILACESSO ASC)
/
ALTER TABLE CRM_PARAMSERVICE
    ADD CONSTRAINT CRM_0122PERFILACESSO  FOREIGN KEY  (NRPERFILACESSO)
       REFERENCES PERFILACESSO (NRPERFILACESSO)
/
CREATE TABLE CRM_EMAILORG
(
    NREMAILORG         	NUMBER                 		NOT NULL,
    NRFILAATENDIMENTO  	NUMBER                 		NULL    ,
    NRTPARVPROD        	NUMBER                 		NULL    ,
    NRARVOREPROD       	NUMBER                 		NULL    ,
    CDPRODUTO          	VARCHAR2(10)        	NULL    ,
    NRPERFILACESSO     	NUMBER                 		NOT NULL,
    NMEMAILORG         	VARCHAR2(200)          	NOT NULL,
    DSEMAILORG         	VARCHAR2(300)          	NOT NULL,
    DSEMAILORGENC      	VARCHAR2(300)          	NULL    ,
    TXHOSTIMAP         	VARCHAR2(200)          	NULL    ,
    TXUSERIMAP         	VARCHAR2(200)          	NULL    ,
    TXPASSIMAP         	VARCHAR2(200)          	NULL    ,
    NRORG              		NUMBER                		DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
    DTINCLUSAO         	DATE                   		DEFAULT SYSDATE NOT NULL,
    DTULTATU           		DATE                   		NULL    ,
    NRORGINCLUSAO      	NUMBER                 		DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
    CDOPERINCLUSAO     	VARCHAR2(12)           	DEFAULT '1' NOT NULL,
    NRORGULTATU        	NUMBER                		DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
    CDOPERULTATU       	VARCHAR2(12)           	DEFAULT '1' NOT NULL,
    IDATIVO            		VARCHAR2(1)            	DEFAULT 'S' NOT NULL
	CONSTRAINT CKCIDATIVOCRM_EMAILORG CHECK (IDATIVO IN ('S','N')),
	CONSTRAINT CRM_EMAILORG_PK PRIMARY KEY (NREMAILORG)
)
/
CREATE INDEX FKCRM_0085_CRM_EMAILORG ON CRM_EMAILORG (NRFILAATENDIMENTO ASC)
/
CREATE INDEX FKCRM_0087_CRM_EMAILORG ON CRM_EMAILORG (NRTPARVPROD ASC, NRARVOREPROD ASC)
/
CREATE INDEX FKCRM_0088_CRM_EMAILORG ON CRM_EMAILORG (CDPRODUTO ASC)
/
CREATE INDEX FKCRM_0102_CRM_EMAILORG ON CRM_EMAILORG (NRPERFILACESSO ASC)
/
ALTER TABLE CRM_EMAILORG
    ADD CONSTRAINT CRM_0085FILATENDIMENTO FOREIGN KEY  (NRFILAATENDIMENTO)
       REFERENCES CRM_FILATENDIMENTO (NRFILAATENDIMENTO)
/
ALTER TABLE CRM_EMAILORG
    ADD CONSTRAINT CRM_0087ESTRUARVOREPROD  FOREIGN KEY  (NRTPARVPROD, NRARVOREPROD)
       REFERENCES ESTRUARVOREPROD (NRTPARVPROD, NRARVOREPROD)
/
ALTER TABLE CRM_EMAILORG
    ADD CONSTRAINT CRM_0088PRODUTO  FOREIGN KEY  (CDPRODUTO)
       REFERENCES PRODUTO (CDPRODUTO)
/
ALTER TABLE CRM_EMAILORG
    ADD CONSTRAINT CRM_0102PERFILACESSO  FOREIGN KEY  (NRPERFILACESSO)
       REFERENCES PERFILACESSO (NRPERFILACESSO)