ALTER TABLE FCT_ITEMORCAMENTO ADD CDTPMEDIDAVARIAVEL NUMBER NULL
/
CREATE TABLE FCT_RELACSERVMEDIDAORCA
(
    NRSERVMEDORCA				NUMBER  						NOT NULL,
    NRSEQORCAMENTO  	   		NUMBER 							NOT NULL,
    CDSERVORCA      	   		NUMBER 							NOT NULL,
    CDSERVORCARELAC 	   		NUMBER 							NOT NULL,
    CDTPMEDIDASERV  	   		NUMBER,
    QTMEDIDASERV    	   		NUMBER,
    IDMEDIDAFIXA    	   		VARCHAR2(1),
    NRORG                  		NUMBER          DEFAULT         SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
    IDATIVO                 	VARCHAR2(1)     DEFAULT 'S' 	NOT NULL
      CONSTRAINT CKC_IDATIVO_FCT_RELSEVMEDORC CHECK (IDATIVO IN ('S','N')),
    DTINCLUSAO              	DATE                       		NULL,
    DTULTATU                	DATE                       		NULL,
    NRORGINCLUSAO           	NUMBER          DEFAULT 1   	NULL,
    CDOPERINCLUSAO          	VARCHAR2(12)    DEFAULT '1' 	NULL,
    NRORGULTATU             	NUMBER          DEFAULT 1   	NULL,
    CDOPERULTATU            	VARCHAR2(12)    DEFAULT '1',
	CONSTRAINT PK_RELACSERVMEDORCA PRIMARY KEY(NRSERVMEDORCA)
)
/
ALTER TABLE FCT_RELACSERVMEDIDAORCA ADD CONSTRAINT FKSM00191ORCA_SERVMEDORCA FOREIGN KEY(NRSEQORCAMENTO)
  REFERENCES FCT_ORCAMENTO(NRSEQORCAMENTO) ON DELETE CASCADE
/
ALTER TABLE FCT_RELACSERVMEDIDAORCA ADD CONSTRAINT FKSM00192SERVICO_SERVMEDORCA FOREIGN KEY (CDSERVORCA)
  REFERENCES FCT_SERVICOORCA(CDSERVORCA)
/
ALTER TABLE FCT_RELACSERVMEDIDAORCA ADD CONSTRAINT FKSM00193TPMEDIDA_SERVMEDORCA FOREIGN KEY (CDTPMEDIDASERV)
  REFERENCES FCT_TIPOMEDIDASERV (CDTPMEDIDASERV)
/
ALTER TABLE FCT_RELACSERVMEDIDAORCA ADD CONSTRAINT CK_MEDFIXA_SERVMEDORCA CHECK (IDMEDIDAFIXA IN('S', 'N'))