

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


-------------------------------------------------------------------------------
-- NC836_UPDATE_SYBASE.SQL	       *DO NOT EDIT*		Data Store Version: 836		 
-------------------------------------------------------------------------------

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

CREATE TABLE B_NC_TASK(
   PK_TASK_ID                    INTEGER NOT NULL,
   NAME                          NVARCHAR(255) NULL,
   DESCRIPTION                   NVARCHAR(1000) NULL,
   FK_BIE_ID                     INTEGER NULL,
   THRESHOLD                     INTEGER NULL,
   WEIGHTS                       NVARCHAR(200) NULL,
   TASK_TYPE                     INTEGER NULL,
   DATEFORMAT                    CHAR(19) NULL,
   DETECTION_OPTION              INTEGER NULL,
   LASTMOD_TIME                  DATETIME DEFAULT GETDATE(),
   MODCOUNT                      INTEGER DEFAULT (-1),
   LASTMOD_BY                    CHAR(40) NULL,
   LOCATION_ROOT 		 NVARCHAR(256) NULL,
   OBJECT_CLASS 		 NVARCHAR(256) NULL,
   OWNED_BY 			 NVARCHAR(1024) NULL
) 
go

CREATE TABLE B_NC_TASKSCHEDULE(
   PK_TASKSCHEDULE_ID            INTEGER NOT NULL,
   FK_TASK_ID                    INTEGER NULL,
   NAME                          NVARCHAR(255) NULL,
   DESCRIPTION                   NVARCHAR(1000) NULL,
   LASTMOD_BY                    CHAR(40) NULL,
   MODCOUNT                      INTEGER DEFAULT (-1) NOT NULL,
   RUN_REQUIREMENTS              INTEGER NULL,
   LAST_EXECUTION_AT             NUMERIC(19) NULL,
   NEXT_EXECUTION_REQUEST        NUMERIC(19) NULL,
   SCHEDULE_DELAY                NUMERIC(19) NULL,
   DELETE_AFTER_LAST_RUN         INTEGER NULL,
   PRIORITY			 INTEGER DEFAULT (3) NOT NULL,
   SCHEDULED_BY 		 NVARCHAR(1024) NULL
) 
go

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

INSERT INTO B_NC_TASKSCHEDULE (PK_TASKSCHEDULE_ID, FK_TASK_ID, NAME, DESCRIPTION, LASTMOD_BY, MODCOUNT, RUN_REQUIREMENTS, LAST_EXECUTION_AT, NEXT_EXECUTION_REQUEST, SCHEDULE_DELAY, DELETE_AFTER_LAST_RUN, PRIORITY, SCHEDULED_BY) 
SELECT PK_TASKSCHEDULE_ID, FK_TASK_ID, NAME, DESCRIPTION, LASTMOD_BY, MODCOUNT, RUN_REQUIREMENTS, LAST_EXECUTION_AT, NEXT_EXECUTION_REQUEST, SCHEDULE_DELAY, DELETE_AFTER_LAST_RUN, PRIORITY, SCHEDULED_BY
FROM NC_TASKSCHEDULE
go

INSERT INTO B_NC_TASK (PK_TASK_ID, NAME, DESCRIPTION, FK_BIE_ID, THRESHOLD, WEIGHTS, TASK_TYPE, DATEFORMAT, DETECTION_OPTION, LASTMOD_TIME, MODCOUNT, LASTMOD_BY, LOCATION_ROOT, OBJECT_CLASS, OWNED_BY)
SELECT PK_TASK_ID, NAME, DESCRIPTION, FK_BIE_ID, THRESHOLD, WEIGHTS, TASK_TYPE, DATEFORMAT, DETECTION_OPTION, LASTMOD_TIME, MODCOUNT, LASTMOD_BY, LOCATION_ROOT, OBJECT_CLASS, OWNED_BY
FROM NC_TASK
go

-------------------------------------------------------------------------------
--$120-- foreign keys drop begin
-------------------------------------------------------------------------------

ALTER TABLE NC_TASKSCHEDULE DROP CONSTRAINT F1N_TASKSCHEDULE
go

ALTER TABLE R_TASKSCHEDULE_SCHEDULE DROP CONSTRAINT F1R_TASKSCHEDULE_S
go

ALTER TABLE R_MESSAGESTRUCT_TASK DROP CONSTRAINT F2R_MESSAGESTRUCT_
go

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

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

DROP TABLE NC_TASK
go

DROP TABLE NC_TASKSCHEDULE
go

DROP TABLE NC_TASK_QUEUE
go

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

CREATE TABLE NC_TASK(
   PK_TASK_ID                    INTEGER NOT NULL,
   NAME                          NVARCHAR(255) NULL,
   DESCRIPTION                   NVARCHAR(1000) NULL,
   FK_BIE_ID                     INTEGER NULL,
   THRESHOLD                     INTEGER NULL,
   WEIGHTS                       NVARCHAR(200) NULL,
   TASK_TYPE                     INTEGER NULL,
   DATEFORMAT                    CHAR(19) NULL,
   DETECTION_OPTION              INTEGER NULL,
   LASTMOD_TIME                  DATETIME DEFAULT GETDATE(),
   MODCOUNT                      INTEGER DEFAULT (-1),
   LASTMOD_BY                    CHAR(40) NULL,
   LOCATION_ROOT 		 NVARCHAR(256) NULL,
   OBJECT_CLASS 		 NVARCHAR(256) NULL,
   OWNED_BY 			 NVARCHAR(1024) NULL
) lock datarows
go


CREATE TABLE NC_TASKSCHEDULE(
   PK_TASKSCHEDULE_ID            INTEGER NOT NULL,
   FK_TASK_ID                    INTEGER NULL,
   NAME                          NVARCHAR(255) NULL,
   DESCRIPTION                   NVARCHAR(1000) NULL,
   LASTMOD_BY                    CHAR(40) NULL,
   MODCOUNT                      INTEGER DEFAULT (-1) NOT NULL,
   RUN_REQUIREMENTS              INTEGER NULL,
   LAST_EXECUTION_AT             NUMERIC(19) NULL,
   NEXT_EXECUTION_REQUEST        NUMERIC(19) NULL,
   SCHEDULE_DELAY                NUMERIC(19) NULL,
   DELETE_AFTER_LAST_RUN         INTEGER NULL,
   PRIORITY			 INTEGER DEFAULT (3) NOT NULL,
   SCHEDULED_BY 		 NVARCHAR(1024) NULL
) lock datarows
go

CREATE TABLE NC_TASK_QUEUE (
	TASK_ID 			CHAR(45) NOT NULL,
	SERVICE_NAME 		NVARCHAR(40) NULL,
	SERVER_GROUP 		NVARCHAR(40) NULL,
	DATE_ENTERED 		NUMERIC(19)NOT NULL,
	TASK 				IMAGE NULL,
	STATUS 				INTEGER NOT NULL,
	PRIORITY 			INTEGER NOT NULL,
	RESTART_ID              CHAR(45) NULL,
	SDS_INSTANCE_ID 	CHAR (32) NULL,
	HISTORY_STORE_ID 	CHAR (34) NULL,
	ACTUAL_EXECUTION_TIME   NUMERIC(19) NULL,
	ACTUAL_COMPLETION_TIME  NUMERIC(19) NULL,
	DISPATCHER_ID		CHAR(45) NULL,
	SCHEDULE_TRIGGER_NAME   NVARCHAR(255) NULL,
	SCHEDULE_TYPE		CHAR(15) NULL,
	ACCOUNT_PATH		NVARCHAR(1024) NULL,
	STOREID 		CHAR(34) NULL,
	OBJECT_CLASS 		CHAR(64) NULL,
	OWNER_STOREID 		NVARCHAR(1024) NULL,
	PROCESS_ID          INTEGER NULL
) lock datarows
go

-------------------------------------------------------------------------------
--$201-- indices create begin
-------------------------------------------------------------------------------

CREATE INDEX I1N_TASKSCHEDULE ON NC_TASKSCHEDULE (
   FK_TASK_ID)
go

CREATE INDEX IX_NC_TSK_Q_SLTR ON NC_TASK_QUEUE (
	STATUS, SERVICE_NAME, SERVER_GROUP, DATE_ENTERED)
go

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

ALTER TABLE NC_TASK
   ADD CONSTRAINT PN_TASK PRIMARY KEY (PK_TASK_ID)
go

ALTER TABLE NC_TASKSCHEDULE
   ADD CONSTRAINT PN_TASKSCHEDULE PRIMARY KEY (PK_TASKSCHEDULE_ID)
go

ALTER TABLE NC_TASK_QUEUE ADD CONSTRAINT PN_TASK_QUEUE PRIMARY KEY (TASK_ID)
go

-------------------------------------------------------------------------------
--$203-- alter tables begin
-------------------------------------------------------------------------------

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

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

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

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

INSERT INTO NC_TASKSCHEDULE (PK_TASKSCHEDULE_ID, FK_TASK_ID, NAME, DESCRIPTION, LASTMOD_BY, MODCOUNT, RUN_REQUIREMENTS, LAST_EXECUTION_AT, NEXT_EXECUTION_REQUEST, SCHEDULE_DELAY, DELETE_AFTER_LAST_RUN, PRIORITY, SCHEDULED_BY) 
SELECT PK_TASKSCHEDULE_ID, FK_TASK_ID, NAME, DESCRIPTION, LASTMOD_BY, MODCOUNT, RUN_REQUIREMENTS, LAST_EXECUTION_AT, NEXT_EXECUTION_REQUEST, SCHEDULE_DELAY, DELETE_AFTER_LAST_RUN, PRIORITY, SCHEDULED_BY
FROM B_NC_TASKSCHEDULE
go

INSERT INTO NC_TASK (PK_TASK_ID, NAME, DESCRIPTION, FK_BIE_ID, THRESHOLD, WEIGHTS, TASK_TYPE, DATEFORMAT, DETECTION_OPTION, LASTMOD_TIME, MODCOUNT, LASTMOD_BY, LOCATION_ROOT, OBJECT_CLASS, OWNED_BY)
SELECT PK_TASK_ID, NAME, DESCRIPTION, FK_BIE_ID, THRESHOLD, WEIGHTS, TASK_TYPE, DATEFORMAT, DETECTION_OPTION, LASTMOD_TIME, MODCOUNT, LASTMOD_BY, LOCATION_ROOT, OBJECT_CLASS, OWNED_BY
FROM B_NC_TASK
go

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

ALTER TABLE NC_TASKSCHEDULE
   ADD CONSTRAINT F1N_TASKSCHEDULE FOREIGN KEY (FK_TASK_ID)
      REFERENCES NC_TASK
go

ALTER TABLE R_TASKSCHEDULE_SCHEDULE
   ADD CONSTRAINT F1R_TASKSCHEDULE_S FOREIGN KEY (FK_TASKSCHEDULE_ID)
      REFERENCES NC_TASKSCHEDULE
go

ALTER TABLE R_MESSAGESTRUCT_TASK
   ADD CONSTRAINT F2R_MESSAGESTRUCT_ FOREIGN KEY (FK_TASK_ID)
      REFERENCES NC_TASK
go

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

DROP TABLE B_NC_TASK
go

DROP TABLE B_NC_TASKSCHEDULE
go

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