/*****************************************************************************
*
* Filename         - $Workfile:   location.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: location table and associated items
*
*                    Notes on definition order:
*                    1. Define after LOCATION_GROUP.
*                    2. Define before BAG
*                       (if not, then drop constraint BAG_FK_LOCATION).
*                    3. Define before BAG_TRACE
*                       (if not then drop constraint BAG_TRACE_FK_LOCATION).
*
* Language         - Oracle SQL*Plus script
*
* Classification   - Commercial In Confidence
*
*          (c) Ultra Electronics Limited, 1997
*
*****************************************************************************/
/****************************************************************************
* @(#)$Workfile:   location.sql  $  $Revision:   1.3  $
*
* 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:   /pvcsarch/db_ora/db/source/live/tables/location.svl  $
 * 
 *    Rev 1.3   21 Jun 2001 14:47:56   tagtrak
 * OR:
 * CR:
 * Re-baseline version 4.0.0 to include patches.
 * 
 *    Rev 1.2   02 Apr 1998 19:43:20   tagtrak
 * OR:
 * CR:
 * REV:
 * Initial Issue
 * See label for concession
 * 
 *    Rev 1.1   26 Feb 1998 11:08:04   tagtrak
 * OR:
 * CR:
 * REV:
 * Initial core product version
 * 
 *    Rev 1.0   22 Oct 1997 11:08:02   tagtrak
 * OR:
 * CR:
 * REV:
 * Initial check-in
*
****************************************************************************/


PROMPT Creating table LOCATION

create table LOCATION (
   LOCATION_CODE                 char(6) NOT NULL,
   SITE_ID                       number(10) NOT NULL,
   LOCATION_DESCRIPTION          varchar2(50) NOT NULL,
   GROUP_NAME                    varchar2(10),
   LAST_USER                     number(10) NOT NULL,
   ARCHIVE_FLAG                  number(10) default 0 NOT NULL,
   IGNORE_FOR_MISSING_BAG        varchar2(1) default 'N' 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 location add ( constraint location_pk primary key (appn_row_id) using index tablespace &1._indexes);

alter table LOCATION add ( constraint location_uk1 unique (LOCATION_CODE) using index tablespace &1._indexes);

alter table location add ( constraint location_fk_location_group foreign key (group_name, site_id) references location_group(name, site_id));

alter table location add ( constraint location_fk_tagtrak_users foreign key (last_user) references tagtrak_users( user_id ));

alter table location add (constraint loc_fk_site_info foreign key(site_id)references site_info(site_id));

alter table location add (constraint loc_ignore_for_missing_bag check (ignore_for_missing_bag in ('Y','N')));

CREATE INDEX location_sk1 ON location(group_name) TABLESPACE &1._indexes;

CREATE INDEX location_sk2 ON location(last_user) TABLESPACE &1._indexes;

CREATE INDEX location_sk3 ON location(site_id) TABLESPACE &1._indexes;

COMMENT ON TABLE LOCATION IS 'This table contains details of all the locations at the airport';

COMMENT ON COLUMN LOCATION.ARCHIVE_FLAG IS  'This field is no longer used';
COMMENT ON COLUMN LOCATION.GROUP_NAME IS  'Group name';
COMMENT ON COLUMN LOCATION.LAST_USER IS  'User identifier of the last user to update this row';
COMMENT ON COLUMN LOCATION.IGNORE_FOR_MISSING_BAG IS 'Whether to ignore this location for missing bag searches. Constrained to Y or N';
COMMENT ON COLUMN LOCATION.LOCATION_CODE IS  'Location code';
COMMENT ON COLUMN LOCATION.LOCATION_DESCRIPTION IS  'Location description';
COMMENT ON COLUMN LOCATION.SITE_ID IS  'Site identifier';
COMMENT ON COLUMN LOCATION.APPN_ROW_ID IS 'Unique sequence number for this row';
COMMENT ON COLUMN LOCATION.ROW_CREATE_TIME IS 'The time the row was created';
COMMENT ON COLUMN LOCATION.ROW_DATE_TIME IS 'The time the row was last modified';
COMMENT ON COLUMN LOCATION.CUSER IS 'The user who created the row';
COMMENT ON COLUMN LOCATION.MUSER IS 'The user who last modified the row';
COMMENT ON COLUMN LOCATION.MTERM IS 'The terminal from which the last modifcation to this row was made';
COMMENT ON COLUMN LOCATION.SYSTEM_ID IS 'The system identifier';
COMMENT ON COLUMN LOCATION.SOURCE IS 'The process that last amended this row ';
COMMENT ON COLUMN LOCATION.TO_BE_ARCHIVED IS 'Indicates that this row is to be archived or has been archived';
