CREATE TABLE TIPOPRATCOMUMSERV (
	NRTIPOPRATCOMUMSERV	NUMBER 														NOT NULL,
	CDFILIAL    		VARCHAR2(4) 												NOT NULL,
    CDSERVFILI          VARCHAR2(5)                                                 NOT NULL,
    NRSEQCNFCARD   		NUMBER(3)    												NOT NULL,
	CDFILIALORIG		VARCHAR2(4) 												NOT NULL,
    CDSERVORIG          VARCHAR2(5)                                                 NOT NULL,
    NRSEQCNFCARDORIG	NUMBER(3)   												NOT NULL,
	NRORG 				NUMBER 			DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 	NOT NULL, 
	IDATIVO 			VARCHAR2(1) 	DEFAULT 'S' 								NOT NULL 
		CONSTRAINT CKC_IDATIVO_TIPOPRATCOMUMSERV CHECK (IDATIVO IN ('S','N')),
	DTINCLUSAO 			DATE 			DEFAULT SYSDATE								NULL, 
	DTULTATU 			DATE 			DEFAULT SYSDATE		 						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_NRTIPOPRATCOMUMSERV PRIMARY KEY (NRTIPOPRATCOMUMSERV)
)
/

ALTER TABLE TIPOPRATCOMUMSERV ADD 
	CONSTRAINT FKPLA01285TIPOPRATCOMUMSERV FOREIGN KEY (CDFILIAL, CDSERVFILI,NRSEQCNFCARD) 
		REFERENCES CONFCARD (CDFILIAL, CDSERVFILI, NRSEQCNFCARD) ON DELETE CASCADE
/

CREATE INDEX PLA01285_FK ON TIPOPRATCOMUMSERV (CDFILIAL, CDSERVFILI, NRSEQCNFCARD)
/

ALTER TABLE TIPOPRATCOMUMSERV ADD 
	CONSTRAINT FKPLA01286TPPRATCOMUMSERVORIG FOREIGN KEY (CDFILIALORIG, CDSERVORIG, NRSEQCNFCARDORIG) 
		REFERENCES CONFCARD (CDFILIAL, CDSERVFILI, NRSEQCNFCARD) ON DELETE CASCADE
/

CREATE INDEX PLA01286_FK ON TIPOPRATCOMUMSERV (CDFILIALORIG, CDSERVORIG, NRSEQCNFCARDORIG)
/

ALTER TABLE  TIPOPRATCOMUMSERV ADD CONSTRAINT UNTIPOPRATCOMUMSERV UNIQUE (CDFILIAL, CDSERVFILI, NRSEQCNFCARD, CDFILIALORIG, CDSERVORIG, NRSEQCNFCARDORIG)
/

ALTER TABLE CENARIOCARD ADD NRCENARIOVINCULO NUMBER NULL
/

ALTER TABLE CENARIOCARD ADD 
    CONSTRAINT FKPLA01287CENARIOCARDVINCULO FOREIGN KEY (NRCENARIOVINCULO)
      REFERENCES CENARIOCARD (NRCENARIOCARD) ON DELETE SET NULL
/

CREATE INDEX PLA01287_FK ON CENARIOCARD (NRCENARIOVINCULO)
/

CREATE TABLE CONFCARDMESATIVO (
	NRCONFCARDMESATIVO	NUMBER 														NOT NULL,
	CDFILIAL    		VARCHAR2(4) 												NOT NULL,
    CDSERVFILI          VARCHAR2(5)                                                 NOT NULL,
    NRSEQCNFCARD   		NUMBER(3)    												NOT NULL,
	IDMESATIVO		    VARCHAR2(12) 												NOT NULL,
	NRORG 				NUMBER 			DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 	NOT NULL, 
	IDATIVO 			VARCHAR2(1) 	DEFAULT 'S' 								NOT NULL 
		CONSTRAINT CKC_IDATIVO_CONFCARDMESATIVO CHECK (IDATIVO IN ('S','N')),
	DTINCLUSAO 			DATE 			DEFAULT SYSDATE								NULL, 
	DTULTATU 			DATE 			DEFAULT SYSDATE		 						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_CONFCARDMESATIVO PRIMARY KEY (NRCONFCARDMESATIVO)
)
/

ALTER TABLE CONFCARDMESATIVO ADD 
	CONSTRAINT FKPLA01288CONFCARDMESATIVO FOREIGN KEY (CDFILIAL, CDSERVFILI,NRSEQCNFCARD) 
		REFERENCES CONFCARD (CDFILIAL, CDSERVFILI, NRSEQCNFCARD) ON DELETE CASCADE
/

CREATE INDEX PLA01288_FK ON CONFCARDMESATIVO(CDFILIAL, CDSERVFILI, NRSEQCNFCARD)
/

ALTER TABLE CONFCARDMESATIVO ADD CONSTRAINT UNCONFCARDMESATIVO UNIQUE (CDFILIAL, CDSERVFILI, NRSEQCNFCARD)
/