/*****************************************************************************
*
* Filename         - $Workfile:   bsm_data.sql         $
*
* Author           - Rob Cooke
*
* Project Name     - UltraTrak Core 
*
* Source Code
* Identifier       - Database 
*
* Design Spec
* Section          - 
*
* Contents         - Database script to create live.bsm_data
*
* Language         - Oracle SQL script      
*
* Classification   - Commercial In Confidence
*
*          (c) Ultra Electronics Limited, 2007
*
*****************************************************************************/

PROMPT Creating table BSM_DATA;

CREATE TABLE bsm_data
(
   bsm_id                        NUMBER NOT NULL,
   pax_surname                   CHAR(27),
   pax_id                        NUMBER(10),
   bag_tag                       CHAR(10),
   bag_id                        NUMBER(10),
   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 bsm_data add ( constraint bsm_data_pk primary key (appn_row_id) using index tablespace &1._indexes);

ALTER TABLE bsm_data ADD CONSTRAINT bsm_data_fk FOREIGN KEY (bsm_id) REFERENCES bsm_log (bsm_id) ON DELETE CASCADE;

CREATE INDEX bsm_data_idx_bsm ON bsm_data (bsm_id) TABLESPACE &1._indexes;

CREATE INDEX bsm_data_idx_pax ON bsm_data (pax_id, substr(bag_tag, 2, 9)) TABLESPACE &1._indexes;

CREATE INDEX bsm_data_idx_pax_sur ON bsm_data (pax_surname) TABLESPACE &1._indexes;

COMMENT ON TABLE BSM_DATA IS 'This table contains data from BSMs received';

COMMENT ON COLUMN BSM_DATA.BAG_TAG IS  'The ten digit bag tag number';
COMMENT ON COLUMN BSM_DATA.BSM_ID IS  'The identity of the BSM';
COMMENT ON COLUMN BSM_DATA.PAX_SURNAME IS  'Passenger surname';
COMMENT ON COLUMN BSM_DATA.PAX_ID IS  'Passenger identifier';
COMMENT ON COLUMN BSM_DATA.APPN_ROW_ID IS 'Unique sequence number for this row';
COMMENT ON COLUMN BSM_DATA.ROW_CREATE_TIME IS 'The time the row was created';
COMMENT ON COLUMN BSM_DATA.ROW_DATE_TIME IS 'The time the row was last modified';
COMMENT ON COLUMN BSM_DATA.CUSER IS 'The user who created the row';
COMMENT ON COLUMN BSM_DATA.MUSER IS 'The user who last modified the row';
COMMENT ON COLUMN BSM_DATA.MTERM IS 'The terminal from which the last modifcation to this row was made';
COMMENT ON COLUMN BSM_DATA.SYSTEM_ID IS 'The system identifier';
COMMENT ON COLUMN BSM_DATA.SOURCE IS 'The process that last amended this row ';
COMMENT ON COLUMN BSM_DATA.TO_BE_ARCHIVED IS 'Indicates that this row is to be archived or has been archived';
