CREATE TABLE FCT_ALTERAQTMEDPERFACESS (
    NRALTERAQTMEDPERF 	NUMBER 			NOT NULL,
    NRPERFILACESSO   	NUMBER 			NOT NULL,
    NRORG 				NUMBER 			DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
	IDATIVO 			VARCHAR2(1) 	DEFAULT 'S' NOT NULL,
		CONSTRAINT CKC_IDATIVO_FCT_ALTQTMEDPERFAC 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_ALTERAQTMEDPERFACESS ADD CONSTRAINT PK_ALTERAQTMEDPERFACESS PRIMARY KEY (NRALTERAQTMEDPERF)
/

CREATE INDEX SM00275_FK ON FCT_ALTERAQTMEDPERFACESS (NRPERFILACESSO ASC)
/

ALTER TABLE FCT_ALTERAQTMEDPERFACESS ADD 
	CONSTRAINT FKSM00275PERFILACESSO FOREIGN KEY(NRPERFILACESSO) 
		REFERENCES PERFILACESSO(NRPERFILACESSO) ON DELETE CASCADE
/

CREATE TABLE FCT_ALTERAQTMEDOPERADOR (
    NRALTERAQTMEDOPER 	NUMBER 			NOT NULL,
    CDOPERADOR        	VARCHAR2(12) 	NOT NULL,
    NRORG 				NUMBER 			DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
	IDATIVO 			VARCHAR2(1) 	DEFAULT 'S' NOT NULL,
		CONSTRAINT CKC_IDATIVO_FCT_ALTQTMEDOPER 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_ALTERAQTMEDOPERADOR ADD CONSTRAINT PK_ALTERAQTMEDOPERADOR PRIMARY KEY (NRALTERAQTMEDOPER)
/

CREATE INDEX SM00276_FK ON FCT_ALTERAQTMEDOPERADOR (CDOPERADOR ASC)
/

ALTER TABLE FCT_ALTERAQTMEDOPERADOR ADD 
	CONSTRAINT FKSM00276OPERADOR FOREIGN KEY(CDOPERADOR) 
		REFERENCES OPERADOR(CDOPERADOR) ON DELETE CASCADE
/

ALTER TABLE FCT_ITEMORCAMENTO ADD QTMEDIDACALCULADA NUMBER
/

UPDATE FCT_ITEMORCAMENTO
	SET QTMEDIDACALCULADA = QTMEDIDAORCA
/

ALTER TABLE FCT_ITEMCONTRATO ADD QTMEDIDACALCULADA NUMBER
/

UPDATE FCT_ITEMCONTRATO
	SET QTMEDIDACALCULADA = QTMEDIDACONTR