CREATE TABLE FCT_GERACAOPROPOSTA (
    NRGERACAOPROPOSTA  		NUMBER NOT NULL,
    NRORCAMENTOMODELO  		NUMBER NOT NULL,
    DSGERACAOPROPOSTA  		VARCHAR2(4000),
    NRORG             		NUMBER 	     	DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 	NOT NULL,
    IDATIVO           		VARCHAR2(1)     DEFAULT 'S' 					NOT NULL
      CONSTRAINT CKC_IDATIVO_GERACPROP CHECK (IDATIVO IN ('S','N')),
    DTINCLUSAO        		DATE                  						NULL,
    DTULTATU          		DATE                  						NULL,
    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'
)
/

ALTER TABLE FCT_GERACAOPROPOSTA ADD CONSTRAINT PK_FCT_GERACAOPROPOSTA PRIMARY KEY (NRGERACAOPROPOSTA)
/

ALTER TABLE FCT_GERACAOPROPOSTA ADD CONSTRAINT FKSM00346GERACPROP_ORCAMODEL
    FOREIGN KEY (NRORCAMENTOMODELO) REFERENCES FCT_ORCAMENTOMODELO (NRORCAMENTOMODELO)
/

CREATE INDEX SM00346_FK ON FCT_GERACAOPROPOSTA (NRORCAMENTOMODELO ASC)
/

ALTER TABLE FCT_GERACAOPROPOSTA ADD CONSTRAINT CKC_IDATIVO_GERACAOPROPOSTA CHECK (IDATIVO IN ('S', 'N'))
/

CREATE TABLE FCT_ESCOPOGERACAOPROP (
    NRGERACAOPROPOSTA   NUMBER NOT NULL,
    NRTIPOORCAMENTO     NUMBER NOT NULL,
    NRORG             	NUMBER 	     DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
    IDATIVO           	VARCHAR2(1)     DEFAULT 'S' 					NOT NULL
      CONSTRAINT CKC_IDATIVO_ESCOPGERAPROP CHECK (IDATIVO IN ('S','N')),
    DTINCLUSAO        	DATE                  						NULL,
    DTULTATU          	DATE                  						NULL,
    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'
)
/

ALTER TABLE FCT_ESCOPOGERACAOPROP ADD CONSTRAINT PK_FCT_ESCOPOGERACAOPROP PRIMARY KEY (NRGERACAOPROPOSTA, NRTIPOORCAMENTO)
/

ALTER TABLE FCT_ESCOPOGERACAOPROP ADD CONSTRAINT FKSM00347ESCOPGERPROP_GERPROP
    FOREIGN KEY (NRGERACAOPROPOSTA) REFERENCES FCT_GERACAOPROPOSTA (NRGERACAOPROPOSTA) ON DELETE CASCADE
/

CREATE INDEX SM00347_FK ON FCT_ESCOPOGERACAOPROP (NRGERACAOPROPOSTA ASC)
/

ALTER TABLE FCT_ESCOPOGERACAOPROP ADD CONSTRAINT FKSM00348ESCOPGERPROP_TPORCA
    FOREIGN KEY (NRTIPOORCAMENTO) REFERENCES FCT_TIPOORCAMENTO (NRTIPOORCAMENTO)
/

CREATE INDEX SM00348_FK ON FCT_ESCOPOGERACAOPROP (NRTIPOORCAMENTO ASC)
/

ALTER TABLE FCT_ESCOPOGERACAOPROP ADD CONSTRAINT CKC_IDATIVO_ESCOPOGERPROP CHECK (IDATIVO IN ('S', 'N'))
/

CREATE TABLE FCT_COMPSERVGERACAOPROP (
    NRCOMPSERVGERACAOPROP 	NUMBER NOT NULL,
    NRGERACAOPROPOSTA     	NUMBER NOT NULL,
    NRCOMPSERVICO         	NUMBER NOT NULL,
    NRCOMPSERVICOPAI      	NUMBER,
    IDCOMPOBRIGATORIA     	VARCHAR2(1),
    IDESCOLHIDO           	VARCHAR2(1),
    NRORG             		NUMBER 	     DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
    IDATIVO           		VARCHAR2(1)     DEFAULT 'S' 					NOT NULL
      CONSTRAINT CKC_IDATIVO_COMPSERVGERAPROP CHECK (IDATIVO IN ('S','N')),
    DTINCLUSAO        		DATE                  						NULL,
    DTULTATU          		DATE                  						NULL,
    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'
)
/

ALTER TABLE FCT_COMPSERVGERACAOPROP ADD CONSTRAINT PK_FCT_COMPSERVGERACAOPROP PRIMARY KEY (NRCOMPSERVGERACAOPROP)
/

ALTER TABLE FCT_COMPSERVGERACAOPROP ADD CONSTRAINT FKSM00349COMPSERVGP_GERACPROP
    FOREIGN KEY (NRGERACAOPROPOSTA) REFERENCES FCT_GERACAOPROPOSTA (NRGERACAOPROPOSTA) ON DELETE CASCADE
/

CREATE INDEX SM00349_FK ON FCT_COMPSERVGERACAOPROP (NRGERACAOPROPOSTA ASC)
/

ALTER TABLE FCT_COMPSERVGERACAOPROP ADD CONSTRAINT FKSM00350COMPSERVGP_COMPSERV
    FOREIGN KEY (NRCOMPSERVICO) REFERENCES FCT_COMPSERVICO (NRCOMPSERVICO)
/

CREATE INDEX SM00350_FK ON FCT_COMPSERVGERACAOPROP (NRCOMPSERVICO ASC)
/

CREATE TABLE FCT_ELEMENTOGERACAOPROP (
    NRELEMENTOGERACAOPROP 	NUMBER NOT NULL,
    NRGERACAOPROPOSTA     	NUMBER NOT NULL,
    NRCOMPSERVICO         	NUMBER NOT NULL,
    NRITCOMPSERVICO       	NUMBER NOT NULL,
    IDELEMENTO            	VARCHAR2(100) NOT NULL,
    IDELEMENTOPAI         	VARCHAR2(100),
    IDTIPOELEMENTO        	VARCHAR2(1) NOT NULL,
    IDSERVOBRIGCOMP       	VARCHAR2(1) NOT NULL,
    IDESCOLHIDO           	VARCHAR2(1) NOT NULL,
    NRORG             		NUMBER 	     DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
    IDATIVO           		VARCHAR2(1)     DEFAULT 'S' 					NOT NULL
      CONSTRAINT CKC_IDATIVO_ELEMENGERACPROP CHECK (IDATIVO IN ('S','N')),
    DTINCLUSAO        		DATE                  						NULL,
    DTULTATU          		DATE                  						NULL,
    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'
)
/

ALTER TABLE FCT_ELEMENTOGERACAOPROP ADD CONSTRAINT PK_FCT_ELEMENTOGERACAOPROP PRIMARY KEY (NRELEMENTOGERACAOPROP)
/

ALTER TABLE FCT_ELEMENTOGERACAOPROP ADD CONSTRAINT FKSM00351ELEMENTGP_GERACPROP
    FOREIGN KEY (NRGERACAOPROPOSTA) REFERENCES FCT_GERACAOPROPOSTA (NRGERACAOPROPOSTA) ON DELETE CASCADE
/

CREATE INDEX SM00351_FK ON FCT_ELEMENTOGERACAOPROP (NRGERACAOPROPOSTA ASC)
/

ALTER TABLE FCT_ELEMENTOGERACAOPROP ADD CONSTRAINT FKSM00352ELEMENTGP_COMPSERV
    FOREIGN KEY (NRCOMPSERVICO) REFERENCES FCT_COMPSERVICO (NRCOMPSERVICO)
/

CREATE INDEX SM00352_FK ON FCT_ELEMENTOGERACAOPROP (NRCOMPSERVICO ASC)
/


CREATE TABLE FCT_MEDVARGERACAOPROP (
    NRGERACAOPROPOSTA   NUMBER NOT NULL,
    IDELEMENTORAIZ      VARCHAR2(100) NOT NULL,
    CDTPMEDIDAVARIAVEL  NUMBER NOT NULL,
    QTMINIMA            NUMBER NOT NULL,
    QTMAXIMA            NUMBER NOT NULL,
    QTFRANQUIA          NUMBER,
    NRORG             	NUMBER 	     	DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
    IDATIVO           	VARCHAR2(1)     DEFAULT 'S' 					NOT NULL
      CONSTRAINT CKC_IDATIVO_MEDVARGERACPROP CHECK (IDATIVO IN ('S','N')),
    DTINCLUSAO        	DATE                  						NULL,
    DTULTATU          	DATE                  						NULL,
    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'
)
/

ALTER TABLE FCT_MEDVARGERACAOPROP ADD CONSTRAINT PK_FCT_MEDVARGERACAOPROP PRIMARY KEY (NRGERACAOPROPOSTA, IDELEMENTORAIZ, CDTPMEDIDAVARIAVEL)
/

ALTER TABLE FCT_MEDVARGERACAOPROP ADD CONSTRAINT FKSM00353MEDVARGERPROP_GERPROP
    FOREIGN KEY (NRGERACAOPROPOSTA) REFERENCES FCT_GERACAOPROPOSTA (NRGERACAOPROPOSTA) ON DELETE CASCADE
/

CREATE INDEX SM00353_FK ON FCT_MEDVARGERACAOPROP (NRGERACAOPROPOSTA ASC)
/

ALTER TABLE FCT_MEDVARGERACAOPROP ADD CONSTRAINT FKSM00354MEDVARGERPROP_TPMED
    FOREIGN KEY (CDTPMEDIDAVARIAVEL) REFERENCES FCT_TIPOMEDIDASERV (CDTPMEDIDASERV)
/

CREATE INDEX SM00354_FK ON FCT_MEDVARGERACAOPROP (CDTPMEDIDAVARIAVEL ASC)
/

ALTER TABLE FCT_MEDVARGERACAOPROP ADD CONSTRAINT CKC_IDATIVO_MEDVARGERPROP CHECK (IDATIVO IN ('S', 'N'))
/

CREATE TABLE FCT_ITESCOPOGERACAOPROP (
    NRGERACAOPROPOSTA  	NUMBER NOT NULL,
    NRTIPOORCAMENTO    	NUMBER NOT NULL,
    NRITESCOPOPROPOSTA 	NUMBER NOT NULL,
    IDCONSIDERADO      	VARCHAR2(1) DEFAULT 'S' NOT NULL,
    NRORG             	NUMBER 	     DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
    IDATIVO           	VARCHAR2(1)     DEFAULT 'S' 					NOT NULL
      CONSTRAINT CKC_IDATIVO_ITESCOPGERACPROP CHECK (IDATIVO IN ('S','N')),
    DTINCLUSAO        	DATE                  						NULL,
    DTULTATU          	DATE                  						NULL,
    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'
)
/

ALTER TABLE FCT_ITESCOPOGERACAOPROP ADD CONSTRAINT PK_FCT_ITESCOPOGERACAOPROP PRIMARY KEY (NRGERACAOPROPOSTA, NRTIPOORCAMENTO, NRITESCOPOPROPOSTA)
/

ALTER TABLE FCT_ITESCOPOGERACAOPROP ADD CONSTRAINT FKSM00355ITESCOPGP_GERACPROP
    FOREIGN KEY (NRGERACAOPROPOSTA) REFERENCES FCT_GERACAOPROPOSTA (NRGERACAOPROPOSTA)
/

CREATE INDEX SM00355_FK ON FCT_ITESCOPOGERACAOPROP (NRGERACAOPROPOSTA ASC)
/

ALTER TABLE FCT_ITESCOPOGERACAOPROP ADD CONSTRAINT FKSM00356ITESCOPOGP_TPORC
    FOREIGN KEY (NRTIPOORCAMENTO) REFERENCES FCT_TIPOORCAMENTO (NRTIPOORCAMENTO)
/

CREATE INDEX SM00356_FK ON FCT_ITESCOPOGERACAOPROP (NRTIPOORCAMENTO ASC)
/

ALTER TABLE FCT_ITESCOPOGERACAOPROP ADD CONSTRAINT FKSM00357ITESCOPGP_ITESCOPPROP
    FOREIGN KEY (NRITESCOPOPROPOSTA) REFERENCES FCT_ITESCOPOPROPOSTA (NRITESCOPOPROPOSTA) ON DELETE CASCADE
/

CREATE INDEX SM00357_FK ON FCT_ITESCOPOGERACAOPROP (NRITESCOPOPROPOSTA ASC)
/

ALTER TABLE FCT_ITESCOPOGERACAOPROP ADD CONSTRAINT CKC_IDCONSIDERADO_ITESCOPOGP CHECK (IDCONSIDERADO IN ('S', 'N'))
/

ALTER TABLE FCT_ITESCOPOGERACAOPROP ADD CONSTRAINT CKC_IDATIVO_ITESCOPOGP CHECK (IDATIVO IN ('S', 'N'))
/