ALTER TABLE FCT_NEGCONTRATO ADD IDREALIZARNEGOCIACAO CHAR(1)
/
ALTER TABLE FCT_NEGCONTRATO ADD CONSTRAINT CKC_IDREALIZARNEGOCIACAO CHECK (IDREALIZARNEGOCIACAO IN('M', 'A'))
/
UPDATE FCT_NEGCONTRATO 
  SET IDREALIZARNEGOCIACAO = 'M' 
  WHERE IDREALIZARNEGOCIACAO IS NULL
/


CREATE TABLE FCT_PARCELASAPURNEGCONTRATO (
	NRPARCELASAPURNEGCONTRATO NUMBER 		  NOT NULL,
	NRNEGCONTRATO             NUMBER		  NOT NULL,
	NRFATURACONT              NUMBER 		  NOT NULL,
	VRPARCELANEGOCIA          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_PARCAPURNEGCON CHECK (IDATIVO IN ('S','N'))
)
/
ALTER TABLE FCT_PARCELASAPURNEGCONTRATO ADD CONSTRAINT PK_FCT_PARCELASAPURNEGCONTRATO PRIMARY KEY (NRPARCELASAPURNEGCONTRATO)
/
ALTER TABLE FCT_PARCELASAPURNEGCONTRATO 
  ADD CONSTRAINT FKSM00412PARCAPURNEGCON_NEGCONT FOREIGN KEY (NRNEGCONTRATO)
      REFERENCES FCT_NEGCONTRATO (NRNEGCONTRATO)
/
CREATE INDEX SM00412_FK ON FCT_PARCELASAPURNEGCONTRATO (NRNEGCONTRATO ASC)
/
ALTER TABLE FCT_PARCELASAPURNEGCONTRATO 
  ADD CONSTRAINT FKSM413PARCAPURNEGCON_FATCONT FOREIGN KEY (NRFATURACONT)
      REFERENCES FCT_FATURACONT (NRFATURACONT)
/
CREATE INDEX SM00413_FK ON FCT_PARCELASAPURNEGCONTRATO (NRFATURACONT ASC)
/