/*****************************************************************************
*
* Filename         - $Workfile:   batch_scanner.sql  $
*
*                     Name              Date      Version     CR Number
* Author           - See revision history below.
* Last Update      - See revision history below.
*
* Project Name     - TAGTRAK(Oracle Database)
*
* Source Code
* Identifier       - 0/3/300/8010/112
*
* Design Spec
* Section          - 
*
* Contents         - Live Schema: batch_scanner table and associated items
*
* Language         - Oracle SQL*Plus script
*
* Classification   - Commercial In Confidence
*
*          (c) Ultra Electronics Limited, 1997
*
*****************************************************************************/
/****************************************************************************
* @(#)$Workfile:   batch_scanner.sql  $  $Revision:   1.0  $
*
* 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 batch_scanner;

create table batch_scanner (
   scanner_id                    char(6)  NOT NULL,
   user_id                       number(10) NOT NULL,
   flight_id                     NUMBER(10) NOT NULL,
   batch_flag                    char(1) NOT NULL,
   TIME_INTO_BATCH               date NOT NULL,
   TIME_OUTOF_BATCH	         date,
   UPDATE_STATUS                 char(1) default 'N',
   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 batch_scanner add ( constraint batch_scanner_pk primary key (appn_row_id) using index tablespace &1._indexes);

alter table batch_scanner add ( constraint batch_scanner_fk_flight foreign key (flight_id) references flight (flight_id) on delete cascade);

alter table batch_scanner add ( constraint batch_scanner_fk_scanner_id foreign key (scanner_id) references kit (scanner_id));

alter table batch_scanner add ( constraint batch_scanner_fk_user_id foreign key (user_id) references tagtrak_users (user_id));

alter table batch_scanner add ( constraint batch_scanner_check_flag check ( batch_flag in ('I', 'U', 'O') ));

create index batch_scanner_sk1 on BATCH_SCANNER(flight_id) tablespace  &1._indexes;

CREATE INDEX batch_scanner_sk2 ON batch_scanner(scanner_id) TABLESPACE  &1._indexes;

CREATE INDEX batch_scanner_sk3 ON batch_scanner(user_id) TABLESPACE  &1._indexes;

COMMENT ON TABLE BATCH_SCANNER IS 'This table contains the list of all scanners that are in Batch Mode';

COMMENT ON COLUMN BATCH_SCANNER.BATCH_FLAG IS  'I,O,U  (InBatch, OutOfBatch, Updating)';
COMMENT ON COLUMN BATCH_SCANNER.FLIGHT_ID IS  'The flight identifier';
COMMENT ON COLUMN BATCH_SCANNER.SCANNER_ID IS  'The scanner identifier';
COMMENT ON COLUMN BATCH_SCANNER.TIME_INTO_BATCH IS  'Timestamp when scanner entered Batch Mode';
COMMENT ON COLUMN BATCH_SCANNER.TIME_OUTOF_BATCH IS  'Timestamp when scanner exited Batch Mode';
COMMENT ON COLUMN BATCH_SCANNER.UPDATE_STATUS IS  'Y/N  Y=Actions for scanner had been applied';
COMMENT ON COLUMN BATCH_SCANNER.USER_ID IS  'The user identifier';
COMMENT ON COLUMN BATCH_SCANNER.APPN_ROW_ID IS 'Unique sequence number for this row';
COMMENT ON COLUMN BATCH_SCANNER.ROW_CREATE_TIME IS 'The time the row was created';
COMMENT ON COLUMN BATCH_SCANNER.ROW_DATE_TIME IS 'The time the row was last modified';
COMMENT ON COLUMN BATCH_SCANNER.CUSER IS 'The user who created the row';
COMMENT ON COLUMN BATCH_SCANNER.MUSER IS 'The user who last modified the row';
COMMENT ON COLUMN BATCH_SCANNER.MTERM IS 'The terminal from which the last modifcation to this row was made';
COMMENT ON COLUMN BATCH_SCANNER.SYSTEM_ID IS 'The system identifier';
COMMENT ON COLUMN BATCH_SCANNER.SOURCE IS 'The process that last amended this row ';
COMMENT ON COLUMN BATCH_SCANNER.TO_BE_ARCHIVED IS 'Indicates that this row is to be archived or has been archived';
