ALTER TABLE PARAMGERAL DROP CONSTRAINT FK_PARAMGERALGRUPPROD
/

ALTER TABLE PARAMGERAL ADD 
	CONSTRAINT FK_PARAMGERALGRUPPROD FOREIGN KEY (CDGRUPPRODOTMCARD) 
		REFERENCES GRUPPROD (CDGRUPPROD) ON DELETE SET NULL
/

CREATE TABLE GERACAOCARD (
	NRGERACAOCARD 		NUMBER    									NOT NULL,
	CDOPERADOR          VARCHAR2(12) 								NOT NULL,
	DTMESGERACAOCARD    DATE                                        NOT NULL,
        IDTIPORESTRICAO     VARCHAR2(30)                        NOT NULL,
	IDSTATUSGERACAO     VARCHAR2(30)DEFAULT 'ANDAMENTO'             NOT NULL,
	NRORG 			    NUMBER DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 	NOT NULL,
	IDATIVO 		VARCHAR2(1) 	DEFAULT 'S' 								NOT NULL
		CONSTRAINT CKC_IDATIVO_GERACAOCARD 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_GERACAOCARD PRIMARY KEY (NRGERACAOCARD)
)
/
ALTER TABLE GERACAOCARD ADD CONSTRAINT FKPLAXXXXXGERACAOCARD_OPER FOREIGN KEY (CDOPERADOR) REFERENCES OPERADOR (CDOPERADOR)
/
CREATE INDEX FKPLAXXXXXGERACAOCARD_OPER ON GERACAOCARD (CDOPERADOR)
/

CREATE TABLE ITGERACAOCARD (
	NRITGERACAOCARD 	NUMBER    									NOT NULL,
   NRGERACAOCARD 		NUMBER    									NOT NULL,
	CDFILIAL            VARCHAR2(4)                                 NOT NULL,
    CDSERVFILI          VARCHAR2(5) 								NOT NULL,
    DTREFERENCIA        DATE                                        NOT NULL,
    CDTIPOCUSTO         VARCHAR2(2)                                 NULL,
    VRCUSTOPADRAO       FLOAT(126)                                  NULL,
    VRCUSTOMAX          FLOAT(126)                                  NULL,
    VRCUSTOMIN          FLOAT(126)                                  NULL,
    CDGRUPPROD          VARCHAR2(10)                                NULL,
    IDPERMITECONGELAR   VARCHAR2(1)                                 NULL,
    QTDIASCONG          NUMBER                                      NULL,
    NRCENARIOVINCULO    NUMBER                                      NULL,
	IDSTATUSGERACAO     VARCHAR2(30)                                NOT NULL,
    NRCENARIOCARD       NUMBER                                      NULL,
    NRCENARIOPUBLICAR   NUMBER                                      NULL,
	NRORG 			NUMBER 			DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 	NOT NULL,
	IDATIVO 		VARCHAR2(1) 	DEFAULT 'S' 								NOT NULL
		CONSTRAINT CKC_IDATIVO_ITGERACAOCARD 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_ITGERACAOCARD PRIMARY KEY (NRITGERACAOCARD)
)
/
ALTER TABLE ITGERACAOCARD ADD CONSTRAINT FKPLAXXXXXITGERACAOCARD_GER FOREIGN KEY (NRGERACAOCARD) REFERENCES GERACAOCARD (NRGERACAOCARD) ON DELETE CASCADE
/
CREATE INDEX FKPLAXXXXXITGERACAOCARD_GER ON ITGERACAOCARD (NRGERACAOCARD)
/
ALTER TABLE ITGERACAOCARD ADD CONSTRAINT FKPLAXXXXXITGERACAOCARD_SER FOREIGN KEY (CDFILIAL, CDSERVFILI) REFERENCES SERVICO (CDFILIAL, CDSERVFILI)
/
CREATE INDEX FKPLAXXXXXITGERACAOCARD_SER ON ITGERACAOCARD (CDFILIAL, CDSERVFILI)
/
ALTER TABLE ITGERACAOCARD ADD CONSTRAINT FKPLAXXXXXITGERACAOCARD_CUS FOREIGN KEY (CDTIPOCUSTO) REFERENCES TIPOCUSTO (CDTIPOCUSTO)
/
CREATE INDEX FKPLAXXXXXITGERACAOCARD_CUS ON ITGERACAOCARD (CDTIPOCUSTO)
/
ALTER TABLE ITGERACAOCARD ADD CONSTRAINT FKPLAXXXXXITGERACAOCARD_PRD FOREIGN KEY (CDGRUPPROD) REFERENCES GRUPPROD (CDGRUPPROD)
/
CREATE INDEX FKPLAXXXXXITGERACAOCARD_PRD ON ITGERACAOCARD (CDGRUPPROD)
/
ALTER TABLE ITGERACAOCARD ADD CONSTRAINT FKPLAXXXXXITGERACAOCARD_CVI FOREIGN KEY (NRCENARIOVINCULO) REFERENCES CENARIOCARD (NRCENARIOCARD)
/
CREATE INDEX FKPLAXXXXXITGERACAOCARD_CVI ON ITGERACAOCARD (NRCENARIOVINCULO)
/
ALTER TABLE ITGERACAOCARD ADD CONSTRAINT FKPLAXXXXXITGERACAOCARD_CEN FOREIGN KEY (NRCENARIOCARD) REFERENCES CENARIOCARD (NRCENARIOCARD)
/
CREATE INDEX FKPLAXXXXXITGERACAOCARD_CEN ON ITGERACAOCARD (NRCENARIOCARD)
/
ALTER TABLE ITGERACAOCARD ADD CONSTRAINT FKPLAXXXXXITGERACAOCARD_CPB FOREIGN KEY (NRCENARIOPUBLICAR) REFERENCES CENARIOCARD (NRCENARIOCARD)
/
CREATE INDEX FKPLAXXXXXITGERACAOCARD_CPB ON ITGERACAOCARD (NRCENARIOPUBLICAR)
/


CREATE TABLE LOGITGERACAOCARD (
	NRLOGITGERACAOCARD 	NUMBER    									NOT NULL,
    NRITGERACAOCARD 	   NUMBER    									NOT NULL,
	IDTIPOLOG            VARCHAR2(30)                                NOT NULL,
    DSLOGGERACAOCARD    VARCHAR2(250) 								NOT NULL,
    DSLOGINTERNO        VARCHAR2(2000)              NULL,
	NRORG 			NUMBER 			DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 	NOT NULL,
	IDATIVO 		VARCHAR2(1) 	DEFAULT 'S' 								NOT NULL
		CONSTRAINT CKC_IDATIVO_LOGITGERACAOCARD 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_LOGITGERACAOCARD PRIMARY KEY (NRLOGITGERACAOCARD)
)
/
ALTER TABLE LOGITGERACAOCARD ADD CONSTRAINT FKPLAXXXXXLOGITGERACAO_ITGER FOREIGN KEY (NRITGERACAOCARD) REFERENCES ITGERACAOCARD (NRITGERACAOCARD) ON DELETE CASCADE
/
CREATE INDEX FKPLAXXXXXLOGITGERACAO_ITGER ON LOGITGERACAOCARD (NRITGERACAOCARD)
/


ALTER TABLE SERVICO ADD IDOTIMIZADOR VARCHAR2(1) DEFAULT 'N' NOT NULL 
   CONSTRAINT CKC_IDOTIMIZADOR CHECK (IDOTIMIZADOR IN('S','N'))
/

ALTER TABLE ITGERACAOCARD ADD NRLOGINTCARDAMES NUMBER NULL
/

ALTER TABLE ITGERACAOCARD ADD CONSTRAINT FK_LOGOTMPUBLICACAO
   FOREIGN KEY (NRLOGINTCARDAMES) REFERENCES LOGINTCARDAMES (NRLOGINTCARDAMES) ON DELETE SET NULL
/

CREATE INDEX FK_LOGOTMPUBLICACAO ON ITGERACAOCARD(NRLOGINTCARDAMES)
/