CREATE TABLE REGRARESTREPET (
	NRREGRARESTREPET	NUMBER 														NOT NULL,
	NMREGRARESTREPET    VARCHAR2(200)                                               NOT NULL,
    CDFILIAL 			VARCHAR2(4) 												NOT NULL,
    CDSERVFILI 			VARCHAR2(5) 												NOT NULL,
	NRORG 				NUMBER 			DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 	NOT NULL, 
	IDATIVO 			VARCHAR2(1) 	DEFAULT 'S' 								NOT NULL 
		CONSTRAINT CKC_IDATIVO_REGRARESTREPET 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_REGRARESTREPET PRIMARY KEY (NRREGRARESTREPET)
)
/
ALTER TABLE REGRARESTREPET ADD 
	CONSTRAINT FKPLA01276REGRARESTREPET_SERV FOREIGN KEY (CDFILIAL, CDSERVFILI) 
		REFERENCES SERVICO (CDFILIAL, CDSERVFILI)
/

CREATE INDEX PLA01276_FK ON REGRARESTREPET (CDFILIAL, CDSERVFILI)
/

CREATE TABLE RESTRICAOTPPRAT (
	NRRESTRICAOTPPRAT	NUMBER 														NOT NULL,
	NRREGRARESTREPET    NUMBER                                                      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_RESTRICAOTPPRAT 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_RESTRICAOTPPRAT PRIMARY KEY (NRRESTRICAOTPPRAT)
)
/

ALTER TABLE RESTRICAOTPPRAT ADD 
	CONSTRAINT FKPLA01277REGRARESTREPET FOREIGN KEY (NRREGRARESTREPET) 
		REFERENCES REGRARESTREPET (NRREGRARESTREPET) ON DELETE CASCADE
/

CREATE INDEX PLA01277_FK ON RESTRICAOTPPRAT (NRREGRARESTREPET)
/

ALTER TABLE RESTRICAOTPPRAT ADD 
	CONSTRAINT FKPLA01278TIPOPRAT FOREIGN KEY (CDTIPOPRAT) 
		REFERENCES TIPOPRAT (CDTIPOPRAT)
/

CREATE INDEX PLA01278_FK ON RESTRICAOTPPRAT (CDTIPOPRAT)
/

CREATE TABLE RESTRICAOINGRED (
	NRRESTRICAOINGRED	NUMBER 														NOT NULL,
	NRREGRARESTREPET    NUMBER                                                      NOT NULL,
    NRINGREDIENTEPRINC  NUMBER                                                      NULL,
    IDINGREDIENTE1		VARCHAR2(1) 	DEFAULT 'S' 								NOT NULL 
		CONSTRAINT CKC_IDINGR1_RESTRICAOINGRED CHECK (IDINGREDIENTE1 IN ('S','N')),
	IDINGREDIENTE2		VARCHAR2(1) 	DEFAULT 'S' 								NOT NULL 
		CONSTRAINT CKC_IDINGR2_RESTRICAOINGRED CHECK (IDINGREDIENTE2 IN ('S','N')),
    NRORG 				NUMBER 			DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 	NOT NULL, 
	IDATIVO 			VARCHAR2(1) 	DEFAULT 'S' 								NOT NULL 
		CONSTRAINT CKC_IDATIVO_RESTRICAOINGRED 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_RESTRICAOINGRED PRIMARY KEY (NRRESTRICAOINGRED)
)
/

ALTER TABLE RESTRICAOINGRED ADD 
	CONSTRAINT FKPLA01279NRREGRARESTREPET FOREIGN KEY (NRREGRARESTREPET) 
		REFERENCES REGRARESTREPET (NRREGRARESTREPET) ON DELETE CASCADE
/

CREATE INDEX PLA01279_FK ON RESTRICAOINGRED (NRREGRARESTREPET)
/

ALTER TABLE RESTRICAOINGRED ADD 
	CONSTRAINT FKPLA01280INGREDIENTEPRINC FOREIGN KEY (NRINGREDIENTEPRINC) 
		REFERENCES INGREDIENTEPRINC (NRINGREDIENTEPRINC)
/

CREATE INDEX PLA01280_FK ON RESTRICAOINGRED (NRINGREDIENTEPRINC)
/

ALTER TABLE RESTRICAOINGRED ADD 
	CONSTRAINT UN_REGRARESTREPET UNIQUE (NRREGRARESTREPET, NRINGREDIENTEPRINC)
/

UPDATE OTIMIZADORITEM SET NRORDEMITEM = NRORDEMITEM + 1 WHERE NRORDEMITEM >= 18
/

INSERT INTO OTIMIZADORITEM(NROTIMIZADORITEM, DSOTIMIZADORITEM, NRORDEMITEM) VALUES (26, 'RESTRICAO DE REPETICAO DE INGREDIENTES',18) 
/

ALTER TABLE RESTRICAOINGRED ADD IDMESMODIA VARCHAR2(1) DEFAULT 'S' 
  CONSTRAINT CKC_RESTRICAOINGRED_MESMODIA CHECK (IDMESMODIA IN ('S','N'))
/

ALTER TABLE RESTRICAOINGRED ADD IDDIASEGUIDO VARCHAR2(1) DEFAULT 'S' 
  CONSTRAINT CKC_RESTRICAOINGRED_IDDIASEG CHECK (IDDIASEGUIDO IN ('S','N'))
/  

ALTER TABLE CENARIOCARD ADD NRCENARIOCARDORIGINAL NUMBER NULL
/

ALTER TABLE SERVICO ADD NRMESHISTCONS NUMBER NULL
/

ALTER TABLE LOGINTCARDADIA ADD QTCLIESTICAR FLOAT(126) NULL
/

ALTER TABLE LOGINTCARDADIA ADD QTFUNESTICAR FLOAT(126) NULL
/

ALTER TABLE LOGINTCARDADIA ADD QTDOAESTICAR FLOAT(126) NULL
/