/*****************************************************************************
*
* Filename         - $Workfile:   ulds.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: ulds table and associated items
*
* Language         - Oracle SQL*Plus script
*
* Classification   - Commercial In Confidence
*
*          (c) Ultra Electronics Limited, 1997
*
*****************************************************************************/
/****************************************************************************
* @(#)$Workfile:   ulds.sql  $  $Revision:   1.4  $
*
* 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:   /shared/pvcs/aisarch/db_ora/db/source/live/tables/ulds.svl  $
 * 
 *    Rev 1.4   12 Sep 2002 17:46:56   tagtrak
 * OR:
 * CR: 15644
 * DESC: BA BRS Segregation changes
 * 
 *    Rev 1.3   06 Jun 2000 09:53:34   tagtrak
 *  
 * 
 *    Rev 1.2.1.2   10 Jun 1999 14:51:52   tagtrak
 * OR:
 * CR: 14043
 * REV:
 * Changed Archive and Backup so that the database
 * can be accessed during the eraseLive function.
 * 
 * Neil Bishop.
 * 
 *    Rev 1.2   02 Apr 1998 19:43:56   tagtrak
 * OR:
 * CR:
 * REV:
 * Initial Issue
 * See label for concession
 * 
 *    Rev 1.1   26 Feb 1998 11:08:34   tagtrak
 * OR:
 * CR:
 * REV:
 * Initial core product version
 * 
 *    Rev 1.0   22 Oct 1997 11:08:28   tagtrak
 * OR:
 * CR:
 * REV:
 * Initial check-in
*
****************************************************************************/

PROMPT Creating table ULDS

create table ULDS (
   ULD_NO                        char(10) NOT NULL,
   FLIGHT_ID                     number(10) NOT NULL,
   ULD_HOLD_NO                   char(6) NULL,
   ULD_NO_OF_BAGS                number(6) default 0 NOT NULL,
   NEXT_BAG_SEQ_NO               number(6) default 1 NOT NULL,
   ULD_LOADED_STATUS             char(1) default 'N' NOT NULL,
   ULD_CATEGORY                  varchar2(5) NOT NULL,
   ULD_TYPE                      char(1) NOT NULL,
   CONNECTION_TYPE               char(6) NULL,
   ULD_LOAD_TIME                 date NULL,
   USER_ID                       number(10) NULL,
   LOCATION_CODE                 char(6) NULL,
   PD_MARKER                     char(1) default 'N' NOT NULL,
   ULD_ID_CODE                   varchar2(10),
   NEXT_FLIGHT_NO                VARCHAR2(8),
   NEXT_FLIGHT_DATE              VARCHAR2(5),
   CLOSE_FLAG                    VARCHAR2(1) default 'N' NOT NULL,
   VOLUME_CODE                   number(1) 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 ulds add ( constraint ulds_pk primary key (appn_row_id) using index tablespace &1._indexes);

alter table ulds add ( constraint ulds_uk1 unique (uld_no,flight_id) using index tablespace &1._indexes );

alter table ulds add ( constraint ulds_fk_flight foreign key (flight_id) references flight (flight_id) on delete cascade);

create index ULDS_IND1 on ULDS(ULD_ID_CODE) tablespace &1._indexes;

create index ulds_sk1 on ulds(flight_id) tablespace &1._indexes;

COMMENT ON TABLE ULDS IS 'This table contains details about the ULDs in the system';

COMMENT ON COLUMN ULDS.VOLUME_CODE IS 'IATA ULD volume code';
COMMENT ON COLUMN ULDS.CLOSE_FLAG IS  'Indicates that the ULD is closed';
COMMENT ON COLUMN ULDS.CONNECTION_TYPE IS  'Connection type';
COMMENT ON COLUMN ULDS.FLIGHT_ID IS  'Flight identifier';
COMMENT ON COLUMN ULDS.LOCATION_CODE IS  'Location code';
COMMENT ON COLUMN ULDS.NEXT_BAG_SEQ_NO IS  'Sequence number of the next bag to be loaded';
COMMENT ON COLUMN ULDS.NEXT_FLIGHT_DATE IS  'Flight date of the next flight';
COMMENT ON COLUMN ULDS.NEXT_FLIGHT_NO IS  'Flight number of the next flight';
COMMENT ON COLUMN ULDS.PD_MARKER IS  'Post depart marker';
COMMENT ON COLUMN ULDS.ULD_CATEGORY IS  'ULD category';
COMMENT ON COLUMN ULDS.ULD_HOLD_NO IS  'ULD hold number';
COMMENT ON COLUMN ULDS.ULD_ID_CODE IS  'ULD identifier code';
COMMENT ON COLUMN ULDS.ULD_LOADED_STATUS IS  'ULD load status';
COMMENT ON COLUMN ULDS.ULD_LOAD_TIME IS  'Time ULD was loaded';
COMMENT ON COLUMN ULDS.ULD_NO IS  'ULD number';
COMMENT ON COLUMN ULDS.ULD_NO_OF_BAGS IS  'Number of bags in the ULD';
COMMENT ON COLUMN ULDS.ULD_TYPE IS  'ULD type';
COMMENT ON COLUMN ULDS.USER_ID IS  'User identifier';
COMMENT ON COLUMN ULDS.APPN_ROW_ID IS 'Unique sequence number for this row';
COMMENT ON COLUMN ULDS.ROW_CREATE_TIME IS 'The time the row was created';
COMMENT ON COLUMN ULDS.ROW_DATE_TIME IS 'The time the row was last modified';
COMMENT ON COLUMN ULDS.CUSER IS 'The user who created the row';
COMMENT ON COLUMN ULDS.MUSER IS 'The user who last modified the row';
COMMENT ON COLUMN ULDS.MTERM IS 'The terminal from which the last modifcation to this row was made';
COMMENT ON COLUMN ULDS.SYSTEM_ID IS 'The system identifier';
COMMENT ON COLUMN ULDS.SOURCE IS 'The process that last amended this row ';
COMMENT ON COLUMN ULDS.TO_BE_ARCHIVED IS 'Indicates that this row is to be archived or has been archived';
