/*****************************************************************************
*
* Filename         - $Workfile:   flight.sql  $
*
*                     Name              Date      Version     CR Number
*                     Martin Helliwell 5/8/2        1.7         15644
* 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: Flight table and associated items
*
* Language         - Oracle SQL*Plus script
*
* Classification   - Commercial In Confidence
*
*          (c) Ultra Electronics Limited, 1997
*
*****************************************************************************/

PROMPT Creating table FLIGHT

create table flight (
   flight_id                     number(10)   not null,
   op_flight_id                  number(10),
   next_leg_id                   NUMBER(10),         
   process_name                  char(20)     not null,
   unit_name                     char(10)     not null,
   flight_no                     char(8)      not null,
   flight_date                   char(5)      not null,
   site_id                       number(10)   not null,
   flight_sch_time               char(4)      not null,
   flight_est_date               char(4)      not null,
   flight_status                 char(2) default 'FO' not null,
   flight_strategy               char(12),
   archive_flag                  number(10) default 0   not null,
   departure_time                date         not null,
   subunit_name                  char(4),
   dcsid                         char(7),
   dcs_flight_no                 char(8),
   carrier_alpha_code            char(3),
   flight_type                   char(1) default 'O',
   security_clearance            CHAR(1) DEFAULT 'N' NOT NULL,
   open_count                    number(6) default 1    not null,
   close_count                   number(6) default 0    not null,
   bvis_subheader                raw(42),
   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 flight add ( constraint flight_pk primary key (appn_row_id) using index tablespace &1._indexes);

alter table flight add ( constraint flight_uk1 unique (flight_id) using index tablespace &1._indexes);

alter table flight add ( constraint flight_uk2 unique (site_id,flight_type,flight_no,flight_date) using index tablespace &1._indexes);

alter table flight add ( constraint flight_fk_system_cfg foreign key (process_name, unit_name, subunit_name, dcsid) references system_cfg (process_name, unit_name, subunit_name, dcsid));

alter table flight add ( constraint flight_fk_site_info foreign key(site_id) references site_info(site_id));

alter table flight add ( constraint flight_fk_carrier foreign key (carrier_alpha_code) references carrier_lookup (alpha_code));

alter table flight add constraint ck_flight_type check(flight_type IN ('I', 'O'));

alter table flight add constraint flight_ch check(security_clearance IN ('N','Y'));

create index flight_sk1 on flight(departure_time) tablespace &1._indexes;
 
create index flight_sk3 on flight(flight_sch_time) tablespace &1._indexes;
 
create index flight_sk8 on flight(flight_date) tablespace &1._indexes;
 
create index flight_sk9 on flight(flight_no) tablespace &1._indexes;

CREATE INDEX flight_sk10 ON flight(carrier_alpha_code) TABLESPACE &1._indexes;

CREATE INDEX flight_sk11 ON flight(process_name, unit_name, subunit_name, dcsid) TABLESPACE &1._indexes;

COMMENT ON TABLE FLIGHT IS 'This table contains information on flights in ths system';

COMMENT ON COLUMN FLIGHT.ARCHIVE_FLAG IS  'Not used';
COMMENT ON COLUMN FLIGHT.BVIS_SUBHEADER IS  'The 42-byte header received from the BVIS DCS interface for this flight.';
COMMENT ON COLUMN FLIGHT.CARRIER_ALPHA_CODE IS  'Carrier code';
COMMENT ON COLUMN FLIGHT.CLOSE_COUNT IS  'The number of times the flight has been closed.';
COMMENT ON COLUMN FLIGHT.DCSID IS  'Part of the unique DCS identifier';
COMMENT ON COLUMN FLIGHT.DCS_FLIGHT_NO IS  'The flight number as received in the originating BSM.';
COMMENT ON COLUMN FLIGHT.DEPARTURE_TIME IS  'Departure time';
COMMENT ON COLUMN FLIGHT.FLIGHT_DATE IS  'Flight date';
COMMENT ON COLUMN FLIGHT.FLIGHT_EST_DATE IS  'Estimated flight date';
COMMENT ON COLUMN FLIGHT.FLIGHT_ID IS  'Flight identifier';
COMMENT ON COLUMN FLIGHT.FLIGHT_NO IS  'Flight number';
COMMENT ON COLUMN FLIGHT.FLIGHT_SCH_TIME IS  'Scheduled time';
COMMENT ON COLUMN FLIGHT.FLIGHT_STATUS IS  'Flight status';
COMMENT ON COLUMN FLIGHT.FLIGHT_STRATEGY IS  'Flight strategy';
COMMENT ON COLUMN FLIGHT.FLIGHT_TYPE IS  'Flight type (inbound or outbound)';
COMMENT ON COLUMN FLIGHT.NEXT_LEG_ID IS  'Flight identifer of the next flight leg';
COMMENT ON COLUMN FLIGHT.OPEN_COUNT IS  'The number of times the flight has been opened.';
COMMENT ON COLUMN FLIGHT.OP_FLIGHT_ID IS  'This is the operating flight of a codeshare';
COMMENT ON COLUMN FLIGHT.PROCESS_NAME IS  'Indicator of how this flight was created or last updated i.e. FIDS, DCS or DUMMY ';
COMMENT ON COLUMN FLIGHT.SECURITY_CLEARANCE IS  'Indicates whether security clearance has been granted';
COMMENT ON COLUMN FLIGHT.SITE_ID IS  'Site identifier';
COMMENT ON COLUMN FLIGHT.SUBUNIT_NAME IS  'Address stamp of the DCS which sent the BSM';
COMMENT ON COLUMN FLIGHT.UNIT_NAME IS  'The UNIT_NAME from the SYSTEM_CFG table for the DCS that this flight was received from.';
COMMENT ON COLUMN FLIGHT.APPN_ROW_ID IS 'Unique sequence number for this row';
COMMENT ON COLUMN FLIGHT.ROW_CREATE_TIME IS 'The time the row was created';
COMMENT ON COLUMN FLIGHT.ROW_DATE_TIME IS 'The time the row was last modified';
COMMENT ON COLUMN FLIGHT.CUSER IS 'The user who created the row';
COMMENT ON COLUMN FLIGHT.MUSER IS 'The user who last modified the row';
COMMENT ON COLUMN FLIGHT.MTERM IS 'The terminal from which the last modifcation to this row was made';
COMMENT ON COLUMN FLIGHT.SYSTEM_ID IS 'The system identifier';
COMMENT ON COLUMN FLIGHT.SOURCE IS 'The process that last amended this row ';
COMMENT ON COLUMN FLIGHT.TO_BE_ARCHIVED IS 'Indicates that this row is to be archived or has been archived';
