CREATE TABLE SYSTEM_EVENTS
 (ROW_CREATE_TIME DATE
 ,ROW_DATE_TIME DATE
 ,CUSER VARCHAR2(30)
 ,MUSER VARCHAR2(30)
 ,MTERM VARCHAR2(64)
 ,SOURCE VARCHAR2(8)
 ,TO_BE_ARCHIVED VARCHAR2(1)
 ,APPN_ROW_ID NUMBER(18) NOT NULL
 ,SYSTEM_ID NUMBER(4) DEFAULT 0 NOT NULL
 ,EVENT_NO NUMBER(3) NOT NULL
 ,EVENT_DESCRIPTION VARCHAR2(255)
 ,EVENT_TYPE VARCHAR2(1) NOT NULL
 ,EVENT_CONTINUATIONS NUMBER(3) NOT NULL
 ,EVENT_ERROR NUMBER(3) NOT NULL
 ,EVENT_DESTINATION NUMBER(6)
 ,EVENT_DATA VARCHAR2(2000) NOT NULL
 ,EVENT_EXPIRY NUMBER(3)
 ,EVENT_ACTIVE VARCHAR2(1)
 ,EVENT_MINUTE NUMBER(2)
 ,EVENT_HOUR NUMBER(2)
 ,MINUTE_REPEATER VARCHAR2(1)
 ,HOUR_REPEATER VARCHAR2(1)
 ,LOG_EVENT VARCHAR2(1)
 ,EVENT_STATE NUMBER(3)
 ,EVENT_TIME_ACTIONED DATE
 ,EVENT_TIME_COMPLETED DATE
 ,EVENT_EXPIRY_TIME DATE
 ,EVENT_REQUESTING_KEY NUMBER(6)
 )
 PCTUSED 90
 PCTFREE 5
 STORAGE
 (
   INITIAL 20K
   NEXT 20K
   PCTINCREASE 0
 ) TABLESPACE APPN_GENERAL_TABLES
/

ALTER TABLE SYSTEM_EVENTS
 ADD (CONSTRAINT SYSTEM_EVENTS_PK PRIMARY KEY
  (APPN_ROW_ID)
 USING INDEX
 PCTFREE 5
 STORAGE
 (
   INITIAL 20K
   NEXT 20K
   PCTINCREASE 0
 ) TABLESPACE APPN_GENERAL_IDXS)
/

ALTER TABLE SYSTEM_EVENTS
 ADD (CONSTRAINT SYSTEM_EVENTS_UK1 UNIQUE
  (EVENT_NO
  ,SYSTEM_ID)
 USING INDEX
 PCTFREE 5
 STORAGE
 (
   INITIAL 20K
   NEXT 20K
   PCTINCREASE 0
 ) TABLESPACE APPN_GENERAL_IDXS)
/

ALTER TABLE SYSTEM_EVENTS
 ADD (CONSTRAINT SYSTEM_EVENTS_EVENT_HOUR CHECK (EVENT_HOUR >= 0))
/

ALTER TABLE SYSTEM_EVENTS
 ADD (CONSTRAINT SYSTEM_EVENTS_EVENT_ACTIVE CHECK (EVENT_ACTIVE IN ('A','G')))
/

ALTER TABLE SYSTEM_EVENTS
 ADD (CONSTRAINT SYSTEM_EVENTS_EVENT_MIN CHECK (EVENT_MINUTE >= 0))
/

ALTER TABLE SYSTEM_EVENTS
 ADD (CONSTRAINT SYSTEM_EVENTS_MIN_REPEATER CHECK (MINUTE_REPEATER IN ('Y','S')))
/

ALTER TABLE SYSTEM_EVENTS
 ADD (CONSTRAINT SYSTEM_EVENTS_EVENT_ERROR CHECK (EVENT_ERROR >= 0))
/

ALTER TABLE SYSTEM_EVENTS
 ADD (CONSTRAINT SYSTEM_EVENTS_EVENT_NO CHECK (EVENT_NO >=0))
/

ALTER TABLE SYSTEM_EVENTS
 ADD (CONSTRAINT SYSTEM_EVENTS_EVENT_CONT CHECK (EVENT_CONTINUATIONS >= 0))
/

ALTER TABLE SYSTEM_EVENTS
 ADD (CONSTRAINT SYSTEM_EVENTS_LOG_EVENT CHECK (LOG_EVENT = 'Y'))
/

ALTER TABLE SYSTEM_EVENTS
 ADD (CONSTRAINT SYSTEM_EVENTS_HOUR_REP_EV_HR CHECK ((HOUR_REPEATER IS NOT NULL
and EVENT_HOUR > 0) OR HOUR_REPEATER IS NULL))
/

ALTER TABLE SYSTEM_EVENTS
 ADD (CONSTRAINT SYSTEM_EVENTS_MIN_REP_EV_MIN CHECK ((MINUTE_REPEATER IS NOT NULL
and EVENT_MINUTE > 0) OR MINUTE_REPEATER IS NULL))
/

ALTER TABLE SYSTEM_EVENTS
 ADD (CONSTRAINT SYSTEM_EVENTS_EVENT_STATE CHECK (EVENT_STATE >= 0))
/

ALTER TABLE SYSTEM_EVENTS
 ADD (CONSTRAINT SYSTEM_EVENTS_EVENT_TYPE CHECK (EVENT_TYPE IN ('L','M','R','S','T','U','W')))
/

ALTER TABLE SYSTEM_EVENTS
 ADD (CONSTRAINT SYSTEM_EVENTS_HR_REPEATER CHECK (HOUR_REPEATER = 'Y'))
/

ALTER TABLE SYSTEM_EVENTS
 ADD (CONSTRAINT SYSTEM_EVENTS_EVENT_EXPIRY CHECK (EVENT_EXPIRY >= 0))
/


