

--
--    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.
--    


-------------------------------------------------------------------------------
--	NC10_UPDATE_MS.SQL			*	DO NOT EDIT	 *			Data Store Version: 10		 
-------------------------------------------------------------------------------

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

CREATE TABLE BC_OBJECTCATALOGUE(
   PK_OID                        INTEGER NOT NULL,
   NAME                          NVARCHAR(255),
   DESCRIPTION                   NVARCHAR(1000),
   SUBTYPE                       SMALLINT,
   TYPE                          INTEGER NOT NULL,
   MODCOUNT                      INTEGER DEFAULT (-1)
)
go

-------------------------------------------------------------------------------
--$110-- backup inserts begin
-------------------------------------------------------------------------------

INSERT INTO BC_OBJECTCATALOGUE (PK_OID, NAME,  DESCRIPTION, SUBTYPE, TYPE, MODCOUNT) SELECT PK_OID, NAME,  DESCRIPTION, SUBTYPE, TYPE, MODCOUNT FROM NC_OBJECTCATALOGUE
go

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

DROP VIEW V_NC_TASK_LINK
go

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

DROP TABLE NC_OBJECTCATALOGUE
go

DROP TABLE NC_EVENTSTATUS
go

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

CREATE TABLE NC_OBJECTCATALOGUE(
   PK_OID                        INTEGER NOT NULL,
   NAME                          NVARCHAR(255),
   DESCRIPTION                   NVARCHAR(1000),
   SUBTYPE                       SMALLINT,
   TYPE                          INTEGER NOT NULL,
   MODCOUNT                      INTEGER DEFAULT (-1),
   CM_VERSION                    INTEGER DEFAULT (-1) 
)
go

CREATE TABLE NC_EVENTSTATUS(
   PK_EVENT_ID                   CHAR(45) NOT NULL,
   EVENT_STATUS                  INTEGER NOT NULL,
   CONVERSATION                  INTEGER
)
go

-------------------------------------------------------------------------------
--$202-- primary keys add begin
-------------------------------------------------------------------------------

ALTER TABLE NC_OBJECTCATALOGUE
   ADD CONSTRAINT PN_OBJECTCATALOGUE PRIMARY KEY (PK_OID)
go

ALTER TABLE NC_EVENTSTATUS
   ADD CONSTRAINT PN_NC_EVENTSTATUS PRIMARY KEY (PK_EVENT_ID)
go

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

CREATE VIEW V_NC_TASK_LINK
AS
SELECT NC_TASK.PK_TASK_ID, NC_TASK.NAME, 
    NC_TASK.DESCRIPTION, 
    NC_OBJECTCATALOGUE.SUBTYPE AS AGENT_SUBTYPE, 
    NC_OBJECTCATALOGUE.TYPE AS AGENT_TYPE, 
    NC_TASK.FK_BIE_ID, NC_TASK.THRESHOLD, 
    NC_TASK.WEIGHTS, NC_TASK.TASK_TYPE, 
    NC_TASK.DATEFORMAT, NC_TASK.DETECTION_OPTION, 
    NC_TASK.LASTMOD_TIME, NC_TASK.MODCOUNT, 
    NC_TASK.LASTMOD_BY, 
    NC_TASKSCHEDULE.PK_TASKSCHEDULE_ID, 
    R_MESSAGESTRUCT_TASK.FK_MESSAGESTRUCT_ID, 
    R_AGENT_ESCALATIONAGENT.FK_CHILD_AGENT_ID, 
    R_RULE_PARAMETER.LITERAL_TYPE, 
    R_RULE_PARAMETER.FK_RULE_ID, 
    NC_RULE.FK_RULETYPE
FROM NC_TASKSCHEDULE RIGHT OUTER JOIN
    NC_TASK INNER JOIN
    NC_OBJECTCATALOGUE ON 
    NC_TASK.PK_TASK_ID = NC_OBJECTCATALOGUE.PK_OID LEFT OUTER
     JOIN
    R_MESSAGESTRUCT_TASK ON 
    NC_TASK.PK_TASK_ID = R_MESSAGESTRUCT_TASK.FK_TASK_ID
     LEFT OUTER JOIN
    R_AGENT_ESCALATIONAGENT ON 
    NC_TASK.PK_TASK_ID = R_AGENT_ESCALATIONAGENT.FK_PARENT_AGENT_ID
     LEFT OUTER JOIN
    R_RULE_PARAMETER ON 
    NC_TASK.PK_TASK_ID = R_RULE_PARAMETER.FK_TASK_ID ON
     NC_TASKSCHEDULE.FK_TASK_ID = NC_TASK.PK_TASK_ID LEFT
     OUTER JOIN
    NC_RULE ON 
    R_RULE_PARAMETER.FK_RULE_ID = NC_RULE.PK_RULE_ID
go



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

INSERT INTO NC_DB_VERSION (DB_VERSION_ID,BUILD) VALUES(10,'build no.')
go

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

INSERT INTO NC_OBJECTCATALOGUE (PK_OID, NAME,  DESCRIPTION, SUBTYPE, TYPE, MODCOUNT) SELECT PK_OID, NAME,  DESCRIPTION, SUBTYPE, TYPE, MODCOUNT FROM BC_OBJECTCATALOGUE
go
 
 -------------------------------------------------------------------------------
 --$250-- backup drop begin
 -------------------------------------------------------------------------------

DROP TABLE BC_OBJECTCATALOGUE
go

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