/*****************************************************************************
*
* Filename         - $Workfile:   contracted_agents.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         - Definition of the contracted_agents table.
*
* Language         - Oracle SQL*Plus script
*
* Classification   - Commercial In Confidence
*
*          (c) Ultra Electronics Limited, 1997
*
*****************************************************************************/
/****************************************************************************
* @(#)$Workfile:   contracted_agents.sql  $  $Revision:   1.2  $
*
* 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/contracted_agents.svl  $
* 
*    Rev 1.2   06 Jun 2000 09:53:16   tagtrak
*  
* 
*    Rev 1.1   02 Apr 1998 19:42:38   tagtrak
* OR:
* CR:
* REV:
* Initial Issue
* See label for concession
* 
*    Rev 1.0   26 Feb 1998 11:15:14   tagtrak
* OR:
* CR:
* REV:
* Initial core product version
*
****************************************************************************/

PROMPT Creating table CONTRACTED_AGENTS

create table contracted_agents (
   airline_alpha_code            char(3) not null,
   agent_code                    char(5) not null,
   last_user                     number(10)              not null,
   archive_flag                  number(10)   default 0  not null,     
   MIN_FLIGHT_NO                 number(4)    default 0 not null,
   MAX_FLIGHT_NO                 number(4)    default 9999 not null,
   flight_type                   char(1)      default 'B' 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 contracted_agents add ( constraint contracted_agents_pk primary key (appn_row_id) using index tablespace &1._indexes);

alter table contracted_agents add ( constraint contracted_agentsa_uk1 unique (airline_alpha_code,min_flight_no,max_flight_no,agent_code,flight_type) using index tablespace &1._indexes);

alter table contracted_agents add ( constraint cont_agents_fk_carrier foreign key (airline_alpha_code) references carrier_lookup(alpha_code));

alter table contracted_agents add ( constraint contracted_agents_fk_agents foreign key (agent_code) references agents( agent_code ));

alter table contracted_agents add ( constraint contracted_agents_flight_type check (flight_type in ('I','O','B')));

COMMENT ON TABLE CONTRACTED_AGENTS IS 'This table contains details contracted agents for each airline';

COMMENT ON COLUMN CONTRACTED_AGENTS.AGENT_CODE IS  'Agent code';
COMMENT ON COLUMN CONTRACTED_AGENTS.AIRLINE_ALPHA_CODE IS  'Airline carrier code';
COMMENT ON COLUMN CONTRACTED_AGENTS.ARCHIVE_FLAG IS  'This field is no longer used.';
COMMENT ON COLUMN CONTRACTED_AGENTS.FLIGHT_TYPE IS  'Flight type';
COMMENT ON COLUMN CONTRACTED_AGENTS.LAST_USER IS  'User identifier of the last user to update this row.';
COMMENT ON COLUMN CONTRACTED_AGENTS.MAX_FLIGHT_NO IS  'Maximum flight number';
COMMENT ON COLUMN CONTRACTED_AGENTS.MIN_FLIGHT_NO IS  'Minimum flight number';
COMMENT ON COLUMN CONTRACTED_AGENTS.APPN_ROW_ID IS 'Unique sequence number for this row';
COMMENT ON COLUMN CONTRACTED_AGENTS.ROW_CREATE_TIME IS 'The time the row was created';
COMMENT ON COLUMN CONTRACTED_AGENTS.ROW_DATE_TIME IS 'The time the row was last modified';
COMMENT ON COLUMN CONTRACTED_AGENTS.CUSER IS 'The user who created the row';
COMMENT ON COLUMN CONTRACTED_AGENTS.MUSER IS 'The user who last modified the row';
COMMENT ON COLUMN CONTRACTED_AGENTS.MTERM IS 'The terminal from which the last modifcation to this row was made';
COMMENT ON COLUMN CONTRACTED_AGENTS.SYSTEM_ID IS 'The system identifier';
COMMENT ON COLUMN CONTRACTED_AGENTS.SOURCE IS 'The process that last amended this row ';
COMMENT ON COLUMN CONTRACTED_AGENTS.TO_BE_ARCHIVED IS 'Indicates that this row is to be archived or has been archived';
