CREATE TABLE FCT_RELACESCOPOANEXOMODCONT (
    NRRELACESCOPOANEXOMODCONT   NUMBER 			NOT NULL,
    NRESCOPOMORCONT             NUMBER 			NOT NULL,
    NRTIPOANEXO                 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_FCT_RELCOPANMODCNT CHECK (IDATIVO IN ('S','N'))
)
/
ALTER TABLE FCT_RELACESCOPOANEXOMODCONT ADD CONSTRAINT PK_FCT_RELACESCOPOANEXOMODCONT PRIMARY KEY (NRRELACESCOPOANEXOMODCONT)
/

ALTER TABLE FCT_RELACESCOPOANEXOMODCONT 
    ADD CONSTRAINT FKSM00435ESCMDCOT_RELANEXMDCNT FOREIGN KEY (NRESCOPOMORCONT)
        REFERENCES FCT_RELACESCOPOMODCONT (NRESCOPOMORCONT) ON DELETE CASCADE
/

CREATE INDEX SM00435_FK ON FCT_RELACESCOPOANEXOMODCONT (NRESCOPOMORCONT ASC)
/
ALTER TABLE FCT_RELACESCOPOANEXOMODCONT
    ADD CONSTRAINT FKSM00436TIPANEX_RELANEXMDCNT FOREIGN KEY (NRTIPOANEXO)
        REFERENCES FCT_TIPOANEXO (NRTIPOANEXO) ON DELETE CASCADE
/

CREATE INDEX SM00436_FK ON FCT_RELACESCOPOANEXOMODCONT (NRTIPOANEXO ASC)
/


ALTER TABLE FCT_RELACESCOPOMODCONT ADD DSEMAILENVDOCPOSAPROV VARCHAR2(4000) 
/
ALTER TABLE FCT_RELACESCOPOMODCONT ADD IDENVEMAILPOSAPROV VARCHAR2(1)
/
ALTER TABLE FCT_RELACESCOPOMODCONT ADD CONSTRAINT CKC_IDENVEMAILPOSAPROV CHECK (IDENVEMAILPOSAPROV IN ('S', 'N'))
/

UPDATE FCT_RELACESCOPOMODCONT
  SET IDENVEMAILPOSAPROV = 'N'
WHERE IDENVEMAILPOSAPROV IS NULL
/
COMMIT
/
