CREATE TABLE PRATOPEDIDOSERV (
	NRPRATOPEDIDOSERV 		NUMBER 						NOT NULL,
	NRITEMPEDIDOSERV 		NUMBER 						NOT NULL,
	CDFILAUXPRAT         	VARCHAR2(4)             	NOT NULL,
	CDPRATO             	VARCHAR2(10)           		NOT NULL,
	CDTIPOPRAT				VARCHAR2(2)					NOT NULL,
	NRORG 					NUMBER 			DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL, 
	IDATIVO 				VARCHAR2(1) 	DEFAULT 'S' NOT NULL 
		CONSTRAINT CKC_IDATIVO_PRATOPEDIDOSERV 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' NULL,
		CONSTRAINT PK_PRATOPEDIDOSERV PRIMARY KEY (NRPRATOPEDIDOSERV)
)
/
ALTER TABLE PRATOPEDIDOSERV ADD 
    CONSTRAINT FKMYO00016ITEMPEDIDOSERV FOREIGN KEY (NRITEMPEDIDOSERV) 
        REFERENCES ITEMPEDIDOSERV (NRITEMPEDIDOSERV) ON DELETE CASCADE
/
CREATE INDEX FKMYO00016ITEMPEDIDOSERV ON PRATOPEDIDOSERV (NRITEMPEDIDOSERV)
/
ALTER TABLE PRATOPEDIDOSERV ADD 
    CONSTRAINT FKMYO00017PRATO FOREIGN KEY (CDFILAUXPRAT, CDPRATO) 
        REFERENCES PRATO (CDFILAUXPRAT, CDPRATO) ON DELETE CASCADE
/
CREATE INDEX FKMYO00017PRATO ON PRATOPEDIDOSERV (CDFILAUXPRAT, CDPRATO)
/
ALTER TABLE PRATOPEDIDOSERV ADD 
    CONSTRAINT FKMYO00018TIPOPRAT FOREIGN KEY (CDTIPOPRAT) 
        REFERENCES TIPOPRAT (CDTIPOPRAT)
/
ALTER TABLE APPCONFIG ADD URLLOGO VARCHAR2(2000) NULL
/
ALTER TABLE PEDIDOSERV ADD CDFILIALNF VARCHAR2(4) NULL
/
ALTER TABLE PEDIDOSERV DROP CONSTRAINT FKMYO00005NOTAFISCAL
/
ALTER TABLE PEDIDOSERV
	ADD CONSTRAINT FKMYO00005NOTAFISCAL FOREIGN KEY(CDFILIALNF, NRLANCTONF)
		REFERENCES NOTAFISCAL (CDFILIAL, NRLANCTONF) ON DELETE SET NULL