ALTER TABLE UTILPRATOSERV ADD IDUTILPRATOSERVSEM2 VARCHAR2(30) DEFAULT 'PREFERENCIAL' NOT NULL
   CONSTRAINT CKC_UTILPRATOSERV_SEM2 CHECK (IDUTILPRATOSERVSEM2 IN ('PREFERENCIAL', 'OBRIGATORIO', 'RESTRICAO'))
/

ALTER TABLE UTILPRATOSERV ADD IDUTILPRATOSERVSEM3 VARCHAR2(30) DEFAULT 'PREFERENCIAL' NOT NULL
   CONSTRAINT CKC_UTILPRATOSERV_SEM3 CHECK (IDUTILPRATOSERVSEM3 IN ('PREFERENCIAL', 'OBRIGATORIO', 'RESTRICAO'))
/

ALTER TABLE UTILPRATOSERV ADD IDUTILPRATOSERVSEM4 VARCHAR2(30) DEFAULT 'PREFERENCIAL' NOT NULL
   CONSTRAINT CKC_UTILPRATOSERV_SEM4 CHECK (IDUTILPRATOSERVSEM4 IN ('PREFERENCIAL', 'OBRIGATORIO', 'RESTRICAO'))
/

ALTER TABLE PARAMGERAL ADD CDGRUPPRODOTMCARD VARCHAR2(10) NULL
/

CREATE INDEX PLA01281_FK ON PARAMGERAL (CDGRUPPRODOTMCARD ASC)
/

ALTER TABLE PARAMGERAL ADD 
	CONSTRAINT FKPLA01281PARAMGERALGRUPPROD FOREIGN KEY (CDGRUPPRODOTMCARD) 
		REFERENCES GRUPPROD (CDGRUPPROD) ON DELETE CASCADE
/

CREATE TABLE CARDIAEVENTO (
    NRCARDIAEVENTO    NUMBER NOT NULL,
    CDFILIAL          VARCHAR2(4) NOT NULL,
    CDSERVFILI        VARCHAR2(5) NOT NULL,
    DTEVENTO          DATE NOT NULL,
    QTCLIESTICAR      FLOAT(126) NULL,
    QTFUNESTICAR      FLOAT(126) NULL,
    QTDOAESTICAR      FLOAT(126) NULL,
	NRORG             NUMBER 	      DEFAULT         SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
    IDATIVO           VARCHAR2(1)     DEFAULT 'S' NOT NULL
      CONSTRAINT CKC_CARDIAEVENTO 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',
        CONSTRAINT PK_CARDIAEVENTO PRIMARY KEY(NRCARDIAEVENTO)
)
/

CREATE INDEX PLA01282_FK ON CARDIAEVENTO (CDFILIAL ASC, CDSERVFILI ASC)
/

ALTER TABLE CARDIAEVENTO ADD 
	CONSTRAINT FKPLA01282CARDIAEVENSERV FOREIGN KEY (CDFILIAL, CDSERVFILI) 
		REFERENCES SERVICO (CDFILIAL, CDSERVFILI) ON DELETE CASCADE
/

ALTER TABLE CARDIAEVENTO ADD 
	CONSTRAINT UN_CARDIAEVENTO UNIQUE (CDFILIAL, CDSERVFILI, DTEVENTO)
/