

--
--    Licensed Materials - Property of IBM
--    
--    BI and PM: JSM
--    
--    (c) Copyright IBM Corp. 2003, 2010.
--    
--    US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
--    


-------------------------------------------------------------------------------
-- NC16_UPDATE_DB2.SQL	       *DO NOT EDIT*		Data Store Version: 16		 
-------------------------------------------------------------------------------

-------------------------------------------------------------------------------
--$100-- backup create begin
-------------------------------------------------------------------------------

CREATE TABLE BK_NC_MESSAGELINE_ELEMENT(
   FK_MESSAGESTRUCT_ID           INTEGER NOT NULL,
   ELEMENT_NUMBER                INTEGER NOT NULL,
   LINE_NO                       INTEGER NOT NULL,
   TEXT                          VARCHAR(3000),
   FK_BIE_TOPIC_ID               INTEGER
);

-------------------------------------------------------------------------------
--$110-- backup inserts begin
-------------------------------------------------------------------------------
 
INSERT INTO BK_NC_MESSAGELINE_ELEMENT (FK_MESSAGESTRUCT_ID,ELEMENT_NUMBER,
LINE_NO,TEXT,FK_BIE_TOPIC_ID) 
SELECT FK_MESSAGESTRUCT_ID,ELEMENT_NUMBER,LINE_NO,TEXT,FK_BIE_TOPIC_ID
FROM NC_MESSAGELINE_ELEMENT WHERE LENGTH(TEXT) < 3001;
    
INSERT INTO BK_NC_MESSAGELINE_ELEMENT (FK_MESSAGESTRUCT_ID,ELEMENT_NUMBER,
LINE_NO,TEXT,FK_BIE_TOPIC_ID) 
SELECT FK_MESSAGESTRUCT_ID,ELEMENT_NUMBER,LINE_NO,TEXT,FK_BIE_TOPIC_ID
FROM NC_MESSAGELINE_ELEMENT WHERE FK_BIE_TOPIC_ID IS NOT NULL;


-------------------------------------------------------------------------------
--$130-- views drop begin
-------------------------------------------------------------------------------

-------------------------------------------------------------------------------
--$140-- tables drop begin
-------------------------------------------------------------------------------

ALTER TABLE NC_MESSAGELINE_ELEMENT
   DROP CONSTRAINT F1N_MESSAGELINE_EL;

ALTER TABLE NC_MESSAGELINE_ELEMENT
   DROP CONSTRAINT PN_MESSAGELINE_ELE;

DROP TABLE NC_MESSAGELINE_ELEMENT;

-------------------------------------------------------------------------------
--$200-- recreate tables begin
-------------------------------------------------------------------------------

CREATE TABLE NC_MESSAGELINE_ELEMENT(
   FK_MESSAGESTRUCT_ID           INTEGER NOT NULL,
   ELEMENT_NUMBER                INTEGER NOT NULL,
   LINE_NO                       INTEGER NOT NULL,
   TEXT                          VARCHAR(3000),
   FK_BIE_TOPIC_ID               INTEGER
);


CREATE INDEX I1N_MESSAGELINE_EL ON NC_MESSAGELINE_ELEMENT (
   FK_MESSAGESTRUCT_ID);
 
CREATE INDEX I2N_MESSAGELINE_EL ON NC_MESSAGELINE_ELEMENT (
   LINE_NO,FK_MESSAGESTRUCT_ID);
 
ALTER TABLE NC_MESSAGELINE_ELEMENT
   ADD CONSTRAINT PN_MESSAGELINE_ELE PRIMARY KEY (LINE_NO,ELEMENT_NUMBER,FK_MESSAGESTRUCT_ID);

ALTER TABLE NC_MESSAGELINE_ELEMENT
   ADD CONSTRAINT F1N_MESSAGELINE_EL FOREIGN KEY (LINE_NO,FK_MESSAGESTRUCT_ID)
      REFERENCES NC_MESSAGELINE;

-------------------------------------------------------------------------------
--$240-- foreign keys add begin
-------------------------------------------------------------------------------


-------------------------------------------------------------------------------
--$210-- views create begin
-------------------------------------------------------------------------------


-------------------------------------------------------------------------------
--$220-- server data inserts begin
-------------------------------------------------------------------------------

INSERT INTO NC_DB_VERSION (DB_VERSION_ID,BUILD) VALUES(16,'build no.');

-------------------------------------------------------------------------------
--$230-- restore inserts begin
-------------------------------------------------------------------------------

INSERT INTO NC_MESSAGELINE_ELEMENT (FK_MESSAGESTRUCT_ID,ELEMENT_NUMBER,
LINE_NO,TEXT,FK_BIE_TOPIC_ID) 
SELECT FK_MESSAGESTRUCT_ID,ELEMENT_NUMBER,
LINE_NO,TEXT,FK_BIE_TOPIC_ID
FROM BK_NC_MESSAGELINE_ELEMENT;


-------------------------------------------------------------------------------
--$250-- backup drop begin
-------------------------------------------------------------------------------

DROP TABLE BK_NC_MESSAGELINE_ELEMENT;

-------------------------------------------------------------------------------
--$260-- end sql by function
-------------------------------------------------------------------------------
--	END NC16_UPDATE_DB2.SQL			*	DO NOT EDIT	 * 		 
-------------------------------------------------------------------------------
