/*****************************************************************************
*
* Filename         - $Workfile:   message_parts.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: message_parts table and associated items
*
* Language         - Oracle SQL*Plus script
*
* Classification   - Commercial In Confidence
*
*          (c) Ultra Electronics Limited, 2006
*
*****************************************************************************/

PROMPT Creating table MESSAGE_PARTS

CREATE TABLE message_parts (
   message_part_id               NUMBER(10)     NOT NULL,
   message_text1                 VARCHAR2(4000) NOT NULL,
   message_text2                 VARCHAR2(96),
   part_no                       NUMBER(3)      NOT NULL,
   timestamp                     DATE           NOT NULL,
   message_id                    NUMBER(10)     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 message_parts add ( constraint message_parts_pk primary key (appn_row_id) using index tablespace &1._indexes);

ALTER TABLE message_parts ADD ( CONSTRAINT message_parts_uk1 unique (message_part_id) USING INDEX TABLESPACE &1._indexes);

ALTER TABLE message_parts ADD ( CONSTRAINT message_parts_uk2 UNIQUE (message_id,part_no) USING INDEX TABLESPACE &1._indexes);

ALTER TABLE message_parts ADD (   CONSTRAINT message_parts_fk FOREIGN KEY ( message_id ) REFERENCES messages( message_id ) ON DELETE CASCADE);

COMMENT ON TABLE MESSAGE_PARTS IS 'This table contains the actual text making up DCS messages, specifically BNS and BMM messages';

COMMENT ON COLUMN MESSAGE_PARTS.MESSAGE_ID IS  'Message identifier';
COMMENT ON COLUMN MESSAGE_PARTS.MESSAGE_PART_ID IS  'Message part identifier';
COMMENT ON COLUMN MESSAGE_PARTS.MESSAGE_TEXT1 IS  'The text making up the DCS message';
COMMENT ON COLUMN MESSAGE_PARTS.MESSAGE_TEXT2 IS  'The text making up the DCS message.  The entire message body is made by simply combining these message text fields';
COMMENT ON COLUMN MESSAGE_PARTS.PART_NO IS  'Which message part this is . the message parts must be transmitted in order';
COMMENT ON COLUMN MESSAGE_PARTS.TIMESTAMP IS  'Message timestamp';
COMMENT ON COLUMN MESSAGE_PARTS.APPN_ROW_ID IS 'Unique sequence number for this row';
COMMENT ON COLUMN MESSAGE_PARTS.ROW_CREATE_TIME IS 'The time the row was created';
COMMENT ON COLUMN MESSAGE_PARTS.ROW_DATE_TIME IS 'The time the row was last modified';
COMMENT ON COLUMN MESSAGE_PARTS.CUSER IS 'The user who created the row';
COMMENT ON COLUMN MESSAGE_PARTS.MUSER IS 'The user who last modified the row';
COMMENT ON COLUMN MESSAGE_PARTS.MTERM IS 'The terminal from which the last modifcation to this row was made';
COMMENT ON COLUMN MESSAGE_PARTS.SYSTEM_ID IS 'The system identifier';
COMMENT ON COLUMN MESSAGE_PARTS.SOURCE IS 'The process that last amended this row ';
COMMENT ON COLUMN MESSAGE_PARTS.TO_BE_ARCHIVED IS 'Indicates that this row is to be archived or has been archived';
