CREATE TABLE FCT_SERVEXCECAOHCM (
	NRSERVEXCECAOHCM   NUMBER  NOT NULL,
	NRSEQMODCONTRA     NUMBER NOT NULL,
	CDSERVORCAEXECHCM  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_SERVEXCECAOHCM CHECK (IDATIVO IN ('S','N'))
)
/
ALTER TABLE FCT_SERVEXCECAOHCM ADD CONSTRAINT PK_FCT_SERVEXCECAOHCM PRIMARY KEY (NRSERVEXCECAOHCM)
/
ALTER TABLE FCT_SERVEXCECAOHCM 
  ADD CONSTRAINT FKSM00437FCT_MODCONTR_SRVXCHCM FOREIGN KEY (NRSEQMODCONTRA)
      REFERENCES FCT_MODELOCONTRATO (NRSEQMODCONTRA) ON DELETE CASCADE
/
CREATE INDEX SM00437_FK ON FCT_SERVEXCECAOHCM (NRSEQMODCONTRA ASC)
/
ALTER TABLE FCT_SERVEXCECAOHCM 
  ADD CONSTRAINT FKSM00438FCT_SERVORC_SRVEXCHCM FOREIGN KEY (CDSERVORCAEXECHCM)
      REFERENCES FCT_SERVICOORCA (CDSERVORCA)
/
CREATE INDEX SM00438_FK ON FCT_SERVEXCECAOHCM (CDSERVORCAEXECHCM ASC)
/
ALTER TABLE FCT_ITEMCONTRATO ADD IDSERVINTEGRAHCM CHAR(1)
/
ALTER TABLE FCT_ITEMCONTRATO ADD CONSTRAINT CKC_IDSERVINTEGRHCM_FCT_ITCONT CHECK (IDSERVINTEGRAHCM IN ('S', 'N'))
/
UPDATE FCT_ITEMCONTRATO
   SET IDSERVINTEGRAHCM = 'S'
 WHERE IDSERVINTEGRAHCM IS NULL