/*****************************************************************************
*
* Filename         - $Workfile:   $
*
*                     Name              Date      Version     CR Number
* Author           - See revision history below.
* Last Update      - See revision history below.
*
* Project Name     - TAGTRAK(Oracle Database)
*
* Source Code
* Identifier       - 
*
* Design Spec
* Section          - 
*
* Contents         - Live Schema: EQ_LOG table and associated items
*
* Language         - Oracle SQL*Plus script
*
* Classification   - Commercial In Confidence
*
*          (c) Ultra Electronics Limited, 2003
*
*****************************************************************************/
/****************************************************************************
* @(#)$Workfile:   $  $Revision:   $
*
* Revision History
*
* Note that user tagtrak is many users. For these users the user
* name is entered as the last line in the change description.
*
* $Log:   $
*
****************************************************************************/

PROMPT Creating table EQ_LOG

create table EQ_LOG (
   EQL_ID                        number(10) not null,
   EQL_SITE_ID                   number(10) not null,
   EQL_KIT_ID                    number(10),
   EQL_KIT_TYPE                  varchar2(15) not null,
   EQL_SERIAL_NUMBER             varchar2(20) not null,
   EQL_USER_ID                   number(10) not null,
   EQL_KIS_ID                    number(10) not null,
   EQL_COMMENT                   varchar2(50),
   EQL_TIMESTAMP                 DATE not null,
   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
);

alter table eq_log add ( constraint eq_log_pk primary key (appn_row_id) using index tablespace &1._indexes);

alter table EQ_LOG add ( constraint eq_log_uk1 unique (EQL_ID) using index tablespace &1._indexes);

alter table EQ_LOG add ( constraint EQ_LOG_FK_SITE_INFO foreign key (EQL_SITE_ID) references SITE_INFO (SITE_ID));

alter table EQ_LOG add ( constraint EQ_LOG_FK_KIT foreign key (EQL_KIT_ID) references KIT (ID) on delete cascade);

alter table EQ_LOG add ( constraint EQ_LOG_FK_KIT_TYPE foreign key (EQL_KIT_TYPE) references KIT_TYPE (TYPE));

alter table EQ_LOG add ( constraint EQ_LOG_FK_TAGTRAK_USERS foreign key (EQL_USER_ID) references TAGTRAK_USERS (USER_ID));

alter table EQ_LOG add ( constraint EQ_LOG_FK_KIT_STATUS foreign key (EQL_KIS_ID) references KIT_STATUS (KIS_ID));

create index EQ_LOG_IX1 on EQ_LOG(EQL_KIT_ID) tablespace &1._indexes;

create index EQ_LOG_IX2 on EQ_LOG(EQL_USER_ID) tablespace &1._indexes;

create index EQ_LOG_IX3 on EQ_LOG(EQL_KIS_ID) tablespace &1._indexes;

CREATE INDEX eq_log_ix4 ON eq_log(eql_kit_type) TABLESPACE &1._indexes;

CREATE INDEX eq_log_ix5 ON eq_log(eql_site_id) TABLESPACE &1._indexes;

COMMENT ON TABLE EQ_LOG IS 'This table contains equipment logs';

COMMENT ON COLUMN EQ_LOG.EQL_COMMENT IS  'User comment for the log';
COMMENT ON COLUMN EQ_LOG.EQL_ID IS  'Unique identifier';
COMMENT ON COLUMN EQ_LOG.EQL_KIS_ID IS  'Associated kit status identifier';
COMMENT ON COLUMN EQ_LOG.EQL_KIT_ID IS  'Associated kit identifier';
COMMENT ON COLUMN EQ_LOG.EQL_KIT_TYPE IS  'Associated kit type';
COMMENT ON COLUMN EQ_LOG.EQL_SERIAL_NUMBER IS  'Serial number of the associated kit';
COMMENT ON COLUMN EQ_LOG.EQL_SITE_ID IS  'Site identifier';
COMMENT ON COLUMN EQ_LOG.EQL_TIMESTAMP IS  'Date and time of the last insert or update';
COMMENT ON COLUMN EQ_LOG.EQL_USER_ID IS  'User associated with this log entry';
COMMENT ON COLUMN EQ_LOG.APPN_ROW_ID IS 'Unique sequence number for this row';
COMMENT ON COLUMN EQ_LOG.ROW_CREATE_TIME IS 'The time the row was created';
COMMENT ON COLUMN EQ_LOG.ROW_DATE_TIME IS 'The time the row was last modified';
COMMENT ON COLUMN EQ_LOG.CUSER IS 'The user who created the row';
COMMENT ON COLUMN EQ_LOG.MUSER IS 'The user who last modified the row';
COMMENT ON COLUMN EQ_LOG.MTERM IS 'The terminal from which the last modifcation to this row was made';
COMMENT ON COLUMN EQ_LOG.SYSTEM_ID IS 'The system identifier';
COMMENT ON COLUMN EQ_LOG.SOURCE IS 'The process that last amended this row ';
COMMENT ON COLUMN EQ_LOG.TO_BE_ARCHIVED IS 'Indicates that this row is to be archived or has been archived';
