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

-- Copyright (C) 2008 Cognos ULC, an IBM Company. All rights reserved.
-- Cognos (R) is a trademark of Cognos ULC, (formerly Cognos Incorporated).


CREATE TABLE CMOBJECTS (
	CMID			int NOT NULL ,
	PCMID			int NOT NULL ,
	VERSION			int default (1)	NOT NULL ,
	CREATED			datetime NOT NULL ,
	MODIFIED		datetime NOT NULL ,
	DISABLED		tinyint NULL ,
	CLASSID			int NOT NULL ,
	DISPSEQ			int default(0) not NULL,
	OWNER			int NULL,
	TENANTID		int default(0) not NULL, 
	CONSTRAINT PK_CMOBJECTS PRIMARY KEY (CMID)
)

create index IDX_CLASS on CMOBJECTS(CLASSID)

create index IDX_CLASS1 on CMOBJECTS(CMID, CLASSID)

create index IDX_PARENT on CMOBJECTS(PCMID)

create index IDX_CREATED on CMOBJECTS(CREATED)

create table CMOBJNAMES (
	CMID			int 			not null,
	LOCALEID		smallint		not null,
	MAPDLOCALEID	smallint,
	ISDEFAULT		bit				not null,
	NAME			nvarchar(256)	not null,
	constraint		PK_CMOBJNAMES	primary key (CMID, LOCALEID)
)

create index IDX_NAME on CMOBJNAMES(NAME)

create trigger CMOBJNAMES_INSORUPD_TR on CMOBJNAMES
instead of insert
as
begin
	set nocount on
	save transaction SAVEPOINT
	if	(select count(*) from inserted) > 1
	begin
		insert into CMOBJNAMES (CMID, LOCALEID, ISDEFAULT, MAPDLOCALEID, NAME) select CMID, LOCALEID, ISDEFAULT, MAPDLOCALEID, NAME from inserted
		if	@@ERROR <> 0
			rollback transaction SAVEPOINT
	end
	else
	begin
		declare @icmid int
		declare @ilocale int
		declare @iname nvarchar(256)
/**/	
		select @icmid=CMID, @ilocale=LOCALEID, @iname=NAME from inserted
		update CMOBJNAMES set NAME=@iname where CMID=@icmid and LOCALEID=@ilocale
		if	@@ROWCOUNT = 0
			insert into CMOBJNAMES (CMID, LOCALEID, ISDEFAULT, MAPDLOCALEID, NAME) select CMID, LOCALEID, ISDEFAULT, MAPDLOCALEID, NAME from inserted
/**/			
		if  @@ERROR <> 0
			rollback transaction SAVEPOINT
	end
end
	
CREATE TABLE CMDATA (
	CMID			int NOT NULL ,
	CONTENTTYPE		varchar (256) NULL ,
	DATASIZE		bigint,
	DATACOMP		bit default(0) not null,
	DATAURI 		varchar (256) NULL,
	DATAPROP		image NULL,
	RESOURCETYPE	varchar (32) NULL,	
	CONSTRAINT PK_CMDATA PRIMARY KEY (CMID)
)

CREATE TABLE CMARCHIVESTATUS (
	CMID			int NOT NULL,
	ARCHSTAT		tinyint default(0) not null, 
	CONSTRAINT PK_CMARCHIVESTATUS PRIMARY KEY (CMID)
)

CREATE TABLE CMSTOREIDS (
	CMID        int NOT NULL,
	STOREID     char(33) NULL,
	CONSTRAINT PK_CMSTOREIDS PRIMARY KEY (CMID)
)

CREATE TABLE CMOBJPROPS1 (
	CMID			int NOT NULL ,
	BUSPHONE		varchar (32) NULL ,
	COMMONNAME		nvarchar (64) NULL ,
	EMAIL			nvarchar (128) NULL ,
	FAXPHONE		varchar (32) NULL ,
	GIVENNAME		nvarchar (64) NULL ,
	HOMEPHONE		varchar (32) NULL ,
	MOBILEPHONE		varchar (32) NULL ,
	PAGERPHONE		varchar (32) NULL ,
	PADDRESS		nvarchar (256) NULL ,
	SURNAME			nvarchar (64) NULL ,
	TIMEZONE		nvarchar (64) NULL ,
	CLOCALEID		smallint NULL ,
	PRODLOCALE		varchar (64) NULL ,
	OBJID			nvarchar (1024) NULL,
	USEACCESSIBILITY	bit  default(0) not null,
	USERNAME		nvarchar (64) NULL,
	ORIENTATION		tinyint NULL ,
	HORIZRENDERLIMIT	int	null,
	VERTRENDERLIMIT		int null,
	MOBILEDEVID		nvarchar (256) NULL ,
	NOTIFICATIONEMAIL	nvarchar (256) NULL ,
	CONSTRAINT PK_CMOBJPROPS1 PRIMARY KEY (CMID)
)

CREATE TABLE CMOBJPROPS10 (
	CMID			int NOT NULL ,
	CONTACTEMAIL	nvarchar (128) NULL ,
	CONTACT			nvarchar (4000) NULL, 
	CONSTRAINT PK_CMOBJPROPS10 PRIMARY KEY (CMID) 
)

CREATE TABLE CMOBJPROPS11 (
	CMID			int NOT NULL ,
	STATUSID		tinyint NULL,
	EVENTID			varchar(45) null,
	OWNEREVENTID		varchar(45) null,
	DISPATCHERID		varchar(50) null,
	MAXDETAILSEVTY		tinyint null,
	SCHEDTRIGNAME		nvarchar(256) null,
	SCHEDTYPE		tinyint null,
	RESTARTEVENTID		varchar(45) null,
	CONSTRAINT PK_CMOBJPROPS11 PRIMARY KEY (CMID) 
)

create index IDX_CMOWNEREVENTID on CMOBJPROPS11(OWNEREVENTID)

create index IDX_CMRESTARTID on CMOBJPROPS11(RESTARTEVENTID)

CREATE TABLE CMOBJPROPS13 (
	CMID			int	NOT NULL,
	ORD				int NOT NULL,
	PARMNAME		nvarchar(256) not null,
	CPARMVALUE		image null,
	constraint PK_CMOBJPROPS13 primary key (CMID, ORD)
)

CREATE TABLE CMOBJPROPS14 (
	CMID			int NOT NULL ,
	RELATED			ntext NULL,
	MYPAGE			ntext null,
	RETENTION		ntext NULL,
	RECIPSEMAIL		ntext NULL,
	CONSTRAINT PK_CMOBJPROPS14 PRIMARY KEY (CMID) 
)

create table CMOBJPROPS15 (
	CMID			int NOT NULL,
	BRSHIAFFINECONS	int null,
	BRSAFFINECONS		int null,
	BRSMAXPROCS		int null,
	METADATAMODEL	nvarchar(4000) null,
	BRSEXECTIMELIMIT	int null,
	BRSDATASOURCECHG	datetime null,
	constraint PK_CMOBJPROPS15 primary key (CMID)
)

create table CMOBJPROPS16 (
	CMID			int not null,
	RSHIAFFINECONS	int null,
	RSAFFINECONS		int null,
	RSMAXPROCS		int null,
	RSQUEUELIMIT		int null,
	RUNNINGSTATE	tinyint	null,
	ADVSETTINGS		nvarchar(4000) null,
	RSEXECTIMELIMIT	int null,
	ROUTINGTABLE	image null,
	constraint PK_CMOBJPROPS16 primary key (CMID)
)

create table CMOBJPROPS17 (
	CMID				int not null,
	NONPEAKBEGINHOUR	tinyint null,
	NONPEAKMAXJOBS		int null,
	PEAKBEGINHOUR		tinyint null,
	PEAKMAXJOBS			int null,
	NEWNONPEAKBEGINHOUR		tinyint null,
	NEWNONPEAKMAXJOBS		int null,
	NEWPEAKBEGINHOUR		tinyint null,
	NEWPEAKMAXJOBS			int null,
	USERCAPABILITY		tinyint	null,
	STARTACTIVE			bit null,
	COMPONENTID			tinyint	null,
	PREVIMGLOCATION		nvarchar(256) NULL,
	RESRCELOCATION		nvarchar(256) NULL,
	constraint PK_CMOBJPROPS17 primary key (CMID)
)

create table CMOBJPROPS18 (
	CMID				int not null,
	OUTPUTREFS			ntext null,
	PATHS				ntext null,
	constraint PK_CMOBJPROPS18 primary key (CMID)
)

CREATE TABLE CMOBJPROPS2 (
	CMID			int NOT NULL ,
	TASKID			varchar (32) NULL ,
	STARTDATE		datetime NULL ,
	ENDDATE			datetime NULL ,
	ENDTYPE			tinyint NULL ,
	EVERYNPERIODS	int NULL ,
	DAILYPERIOD		tinyint NULL ,
	MONTHLYABSDAY	tinyint NULL ,
	MONTHLYRELDAY	tinyint NULL ,
	MONTHLYRELWEEK	tinyint NULL ,
	TYPE			tinyint NULL ,
	YEARLYABSDAY	tinyint NULL ,
	YEARLYABSMONTH	tinyint NULL ,
	YEARLYRELDAY	tinyint NULL ,
	YEARLYRELMONTH	tinyint NULL ,
	YEARLYRELWEEK	tinyint NULL ,
	ACTIVE			bit default(0) NOT NULL,
	WEEKLYMONDAY	bit default(0) NOT NULL ,
	WEEKLYTUESDAY	bit default(0) NOT NULL ,
	WEEKLYWEDNESDAY	bit default(0) NOT NULL ,
	WEEKLYTHURSDAY	bit default(0) NOT NULL ,
	WEEKLYFRIDAY	bit default(0) NOT NULL ,
	WEEKLYSATURDAY	bit default(0) NOT NULL ,
	WEEKLYSUNDAY	bit default(0) NOT NULL, 
	PRIORITY	int NULL,
	INTRARECURSTART		char (13) null,
	INTRARECUREND		char (13) null,
	INTRARECURINTERVAL	varchar (50) null,
	CONSTRAINT PK_CMOBJPROPS2 PRIMARY KEY (CMID) 
)

create index IDX_TASKID on CMOBJPROPS2(TASKID)

create index IDX_PRIORITY on CMOBJPROPS2(PRIORITY)

create table CMOBJPROPS20 (
	CMID               int not null,
	EXECLOCALEID       smallint null,
	EXECFORMAT         tinyint null,
	EXECPAGEORIENT     tinyint null,
	EXECPROMPT         bit  default(1) not null,
	DEFPORTACT         tinyint null,
	ALLOWSUBSCRIBE     bit null,
	ALLOWNOTIFICATION  bit null,
	OBJREFS            ntext null,
	constraint PK_CMOBJPROPS20 primary key (CMID)
)

create table CMOBJPROPS23 (
	CMID			int not null,
	LSAUDITADMINLVL	tinyint null,
	LSAUDITLVL		tinyint	null,
	LSAUDITOTHERLVL	tinyint null,
	LSAUDITUSAGELVL	tinyint null,
	LSAUDITNATIVEQRY	bit null,
	QSRMEMCACHEROOT   nvarchar (256) null,
	constraint PK_CMOBJPROPS23 primary key (CMID)
)

create table CMOBJPROPS24 (
	CMID			int not null,
	LOCATION		nvarchar(512) null,
	MODELNAME		nvarchar(256) null,
	PRINTERADDRESS	nvarchar(2048) null,
	constraint PK_CMOBJPROPS24 primary key (CMID)
)

create table CMOBJPROPS25 (
	CMID				int not null,
	DEPLOYOBJECT		nvarchar (4000) null,
	DEPLOYOBJANC		ntext null,
	DEPLOYOBJCLASSID	int null,
	DEPLOYOBJDEFNAME	nvarchar(256) null,
	DEPLOYOBJDEFSTATUS	tinyint	null,
	DEPLOYOBJUSAGE		tinyint null,
	MESSAGE				image null,
	constraint PK_CMOBJPROPS25 primary key (CMID)
)

CREATE TABLE CMOBJPROPS26 (
	CMID			int not null,
	DELIVOPTIONS		ntext null,
	constraint PK_CMOBJPROPS26 primary key (CMID)
)

CREATE TABLE CMOBJPROPS27 (
	CMID				int not null,
	CUBECONTNAME			nvarchar (1024) NULL,
	GATEWAY				nvarchar (4000) NULL,
	HASPROMPTS			bit  default(0) not null,
	PPOPTIONS			ntext null,
	DATABLOCKS			image null,
	PPDEFPORTACT			tinyint null,
	constraint PK_CMOBJPROPS27 primary key (CMID)
)

CREATE TABLE CMOBJPROPS28 (
	CMID           int   NOT NULL,
	EVENTKEY       ntext NULL,
	EVENTTYPES     ntext NULL,
	FILTERDATAITEM	nvarchar(256) null,
	PARMASSIGN	image NULL,
	SEQUENCING 	tinyint NULL,
	ALLOWNOTIFICATION	bit null,
	DEFPORTACTION		tinyint NULL,
	RUNCOND			tinyint NULL,
	SPEC			ntext NULL,
	CONSTRAINT PK_CMOBJPROPS28 PRIMARY KEY (CMID) 
)

CREATE TABLE CMOBJPROPS3 (
	CMID			int NOT NULL ,
	PROPNAME		varchar(50) NOT NULL,
	LOCALEID		smallint NOT NULL,
	VALUE			nvarchar (3772) NULL,
	ISDEFAULT		bit null,
	MAPDLOCALEID		smallint,
	CONSTRAINT PK_CMOBJPROPS3 PRIMARY KEY (CMID, PROPNAME, LOCALEID) 
)

CREATE TABLE CMOBJPROPS30 (
	CMID            integer not null,
	HANDLE          nvarchar (255) NULL,
	BINDING         ntext NULL,
	REGISTRATION    ntext NULL,
	SERVICEDESCR    ntext NULL,
	LAYOUT          ntext NULL,
	REQUIREDCAP	ntext NULL,
	CANCUSTOMIZE	bit null,
	CONTEXT         ntext NULL,
	DEPLOYREFS	ntext NULL,
	CONSTRAINT PK_CMOBJPROPS30 PRIMARY KEY (CMID)
)

CREATE TABLE CMOBJPROPS31 (
	CMID			int not null,
	ASAUDITLVL		tinyint null,
	BRSAUDITLVL		tinyint	null,
	CMSAUDITLVL		tinyint	null,
	DISPAUDITLVL		tinyint	null,
	DSAUDITLVL		tinyint	null,
	EMSAUDITLVL		tinyint	null,
	JSAUDITLVL		tinyint null,
	MDSAUDITLVL		tinyint	null,
	MMSAUDITLVL		tinyint null,
	MSAUDITLVL		tinyint	null,
	PACSAUDITLVL		tinyint null,
	PDSAUDITLVL		tinyint null,
	PRSAUDITLVL		tinyint null,
	PSAUDITLVL		tinyint null,
	PTSAUDITLVL		tinyint null,
	RSAUDITLVL		tinyint	null,
	SSAUDITLVL		tinyint	null,
	BRSAUDITNATIVEQRY	bit null,
	RSAUDITNATIVEQRY	bit null,
	DISAUDITLVL		tinyint	null,
	RSDATASOURCECHG	datetime null,
	IDSAUDITLVL		tinyint	null,
	ISSAUDITLVL		tinyint	null,
	IUSAUDITLVL		tinyint	null,
	RDSAUDITLVL		tinyint	null,
	RDSMAXDATASIZE		int null,
	MBSAUDITLVL		tinyint	null,
	DDSAUDITLVL		tinyint	null,
	DDSLISPERPRCSR		int null,
	DMSAUDITLVL		tinyint null,
	MISAUDITLVL		tinyint null,
	MDSAFFINECONNECTIONS	int null,
	MDSNONAFFINECONNCTS	int null,
	MDSPEAKCONS		int null,
	MDSPEAKNONAFFINECONNCTS	int null,
	MDSPEAKMAXPROCS 	int null,	
	MDSMAXPROCESSES		int null,	
	MDSEXECUTIONTIMELIMIT	int null,	
	MDSQUEUELIMIT		int null,
	MDINFOURI		nvarchar(4000) null,
	DIMSAUDITLVL		tinyint null,
	EVSAUDITLVL		tinyint null,
	GSAUDITLVL		tinyint null,
	AASAUDITLVL		tinyint null,
	HTSAUDITLVL		tinyint null,
	CMCSAUDITLVL		tinyint null,
	QSAUDITLVL		tinyint null,
	BCSAUDITLVL		tinyint null,
	CSAUDITLVL		tinyint null,
	FSAUDITLVL		tinyint null,
	STSAUDITLVL		tinyint null,
	ANSAUDITLVL		tinyint null,
	RMDSAUDITLVL		tinyint null,
	IDVIZAUDITLVL		tinyint null,
	REPOSAUDITLVL		tinyint null,
	SACAMAUDITLVL		tinyint null,
	constraint PK_CMOBJPROPS31 primary key (CMID)
)

create table CMOBJPROPS32 (
	CMID			int not null,
	STOREDPROCNAME	nvarchar(256) null,
	constraint PK_CMOBJPROPS32 primary key (CMID)
)

CREATE TABLE CMOBJPROPS33 (
	CMID          int NOT NULL,
	NAME          nvarchar(256) null,
	USERID        nvarchar(1024) null,
	LASTLOGIN     datetime null,
	CAPABILITIES  varchar(64) null,
	LICENSE       smallint null,
	constraint PK_CMOBJPROPS33 primary key (CMID)
)

create table CMOBJPROPS34 (
	CMID			int not null,
	ACTION			tinyint null,
	BOOKMARKITEM		nvarchar(256) null,
	BOOKMARKTEXT		nvarchar(256) null,
	DRILLPARMASSIGN		image null,
	SCOPE			image null,
	SPEC			ntext NULL ,
	TARGETOPTIONS		ntext null,
	DEPLOYREFS		ntext NULL,
	constraint PK_CMOBJPROPS34 primary key (CMID)
)

CREATE TABLE CMOBJPROPS35 (
	CMID			int NOT NULL,
	BINDINGNAME		nvarchar (256) null,
	INPUTMESSNAME		nvarchar (256) null,
	OPERATIONNAME		nvarchar (256) null,
	OUTPUTMESSNAME		nvarchar (256) null,
	SERVICENAME		nvarchar (256) null,
	BULKEVENTS		bit null,
	constraint PK_CMOBJPROPS35 primary key (CMID)
)

CREATE TABLE CMOBJPROPS36 (
	CMID			int NOT NULL,
	ACTION			tinyint NULL,
	constraint PK_CMOBJPROPS36 primary key (CMID)
)

CREATE TABLE CMOBJPROPS37 (
	CMID                int NOT NULL,
	ROUTINGHINTS        ntext NULL,
	PROFILESETTINGS     ntext NULL,
	PROFILERANK         int default(0) NOT NULL,
	constraint PK_CMOBJPROPS37 primary key (CMID)
)

CREATE TABLE CMOBJPROPS38 (
	CMID			int NOT NULL ,
	CTITEMCOUNTDEFAULT	int null,
	CTITEMCOUNTLIMIT	int null,
	MBRITEMCOUNTDEFAULT	int null,
	MBRITEMCOUNTLIMIT	int null,
	CONSTRAINT PK_CMOBJPROPS38 PRIMARY KEY (CMID)
)

CREATE TABLE CMOBJPROPS39 (
	PROPID		smallint NOT NULL,
	CMID		int NOT NULL,
	VALUE		tinyint NOT NULL
)

create index IDX_CMOBJPROPS39 on CMOBJPROPS39 (CMID)

CREATE TABLE CMOBJPROPS4 (
	CMID			int NOT NULL ,
	HEIGHT			varchar(20) NULL ,
	WIDTH			varchar(20) NULL ,
	UNIT			tinyint NULL, 
	CONSTRAINT PK_CMOBJPROPS4 PRIMARY KEY (CMID) 
)

CREATE TABLE CMOBJPROPS40 (
	CMID			int NOT NULL ,
	APPGUID			varchar(50) NULL ,
	APPID			nvarchar (256) NULL ,
	APPSTATE		tinyint NULL ,
	APPURL			nvarchar (4000) NULL ,
	CONSTRAINT PK_CMOBJPROPS40 PRIMARY KEY (CMID)
)

CREATE TABLE CMOBJPROPS41 (
	CMID			int NOT NULL ,
	DEPTH			int null,
	ITEMID			nvarchar (256) NULL ,
	PARENTID		nvarchar (256) NULL ,
	CONSTRAINT PK_CMOBJPROPS41 PRIMARY KEY (CMID)
)

CREATE TABLE CMOBJPROPS42 (
	CMID			int NOT NULL ,
	SPEC			ntext NULL ,
	CONSTRAINT PK_CMOBJPROPS42 PRIMARY KEY (CMID)
)

CREATE TABLE CMOBJPROPS43 (
	CMID			int NOT NULL ,
	SPEC			ntext NULL ,
	CONSTRAINT PK_CMOBJPROPS43 PRIMARY KEY (CMID)
)

CREATE TABLE CMOBJPROPS44 (
	CMID			int NOT NULL ,
	RDSGATEWMAPPING		image null,
	CONSTRAINT PK_CMOBJPROPS44 PRIMARY KEY (CMID)
)

CREATE TABLE CMOBJPROPS45 (
	CMID			int NOT NULL,
	LINK			tinyint NULL,
	constraint PK_CMOBJPROPS45 primary key (CMID)
)

CREATE TABLE CMOBJPROPS46 (
	CMID			int NOT NULL,
	DOCTYPE			nvarchar (256) NULL,
	constraint PK_CMOBJPROPS46 primary key (CMID)
)

CREATE TABLE CMOBJPROPS47 (
	CMID			int NOT NULL,
	SYSTEMMETRIC		tinyint NULL,
	PROPERTIES  image null,
	constraint PK_CMOBJPROPS47 primary key (CMID)
)

CREATE TABLE CMOBJPROPS48 (
	CMID			int NOT NULL,
	ASCONNECTIONS		int null,
	CMSCONNECTIONS		int null,
	DDSCONNECTIONS		int null,
	DISCONNECTIONS		int null,
	DSCONNECTIONS		int null,
	IDSCONNECTIONS		int null,
	ISSCONNECTIONS		int null,
	IUSCONNECTIONS		int null,
	JSCONNECTIONS		int null,
	MBSCONNECTIONS		int null,
	MMSCONNECTIONS		int null,
	PACSCONNECTIONS		int null,
	PRSCONNECTIONS		int null,
	PTSCONNECTIONS		int null,
	BRSCHHOTSPOTLIMIT	int null,
	RSCHHOTSPOTLIMIT	int null,
	CAPACITY 		float null,
	LOADBALMODE 		tinyint null,
	DMSCONNECTIONS		int null,
	MISCONNECTIONS		int null,
	PDSCONNECTIONS		int null,
	DSCOMPATTACHLIMIT	int null,
	QSDIAGENABLED		bit null,
	QSMETENABLED		bit null,
	QSQUERYEXECTR		bit null,
	QSPLANTRC		bit null,
	BCSAFFCONS		int null,
	BCSEXECLMT		int null,
	BCSMAXPROCS		int null,
	BCSNONAFFCONS		int null,
	BCSPEAKAFFCONS		int null,
	BCSPEAKMAXPROCS		int null,
	BCSPEAKNONAFFCONS	int null,
	CSAFFCONS		int null,
	CSEXECLMT		int null,
	CSMAXPROCS		int null,
	CSNONAFFCONS		int null,
	CSPEAKAFFCONS		int null,
	CSPEAKMAXPROCS		int null,
	CSPEAKNONAFFCONS	int null,
	FSAFFCONS		int null,
	FSEXECLMT		int null,
	FSCMAXPROCS		int null,
	FSNONAFFCONS		int null,
	FSPEAKAFFCONS		int null,
	FSPEAKMAXPROCS		int null,
	FSPEAKNONAFFCONS	int null,
	RMDSAFFCONS		int null,
	RMDSEXECLMT		int null,
	RMDSNONAFFCONS		int null,
	RMDSPEAKAFFCONS		int null,
	RMDSPEAKNONAFFCONS	int null,
	DASAUDITLVL		tinyint null,
	RMDSCONS		int null,
	RMDSPEAKCONS		int null,
	QSVERBGCLOGLIMIT	int null,
	QSMDQUERYSIZELIMIT	int null,
	QSGENCOMINNATSQL	bit null,
	QSDISVERBGCLOG		bit null,
	QSINITNURSESIZE		int null,
	QSNURSESIZELIMIT	int null,
	QSGCPOLICY		tinyint	null,
	REPOSCACHEOBJTTL	int null,
	REPOSNUMOBJDISK		int null,
	REPOSNUMOBJMEM		int null,	
	MAXSTORESZMB		int null,
	constraint PK_CMOBJPROPS48 primary key (CMID)
)

CREATE TABLE CMOBJPROPS49 (
	CMID			int NOT NULL ,
	URI			nvarchar (4000) NULL ,
	CONSTRAINT PK_CMOBJPROPS49 PRIMARY KEY (CMID) 
)

CREATE TABLE CMOBJPROPS5 (
	CMID			int NOT NULL ,
	ACTEXECTIME		datetime NULL ,
	ACTCOMPTIME		datetime NULL ,
	REQEXECTIME		datetime NULL ,
	USERREF			nvarchar (4000) NULL, 
	DETAILTIME		datetime NULL ,
	DETAIL			ntext NULL,
	SEVERITY		tinyint NULL,
	DETAILTYPE		varchar(64) NULL,
	INFO			ntext NULL, 
	CONSTRAINT PK_CMOBJPROPS5 PRIMARY KEY (CMID) 
)

create index IDX_REQEXECTIME on CMOBJPROPS5(REQEXECTIME)

CREATE TABLE CMOBJPROPS50 (
	CMID            int NOT NULL,
	CONTEXT         image NULL,
	CONTEXTCOUNT    int NULL,
	LASTPAGE        nvarchar(256) null,
	DATADESCRIPTOR  ntext null,
	METADATA        image null,
	CONSTRAINT PK_CMOBJPROPS50 PRIMARY KEY (CMID)
)

CREATE TABLE CMOBJPROPS51 (
	CMID                 int NOT NULL ,
	SERVERGROUP          nvarchar (256) null,
	RUNASOWNER           bit null,
	CANBURST             bit null,
	SCHEDTRIGNAME        nvarchar(256) NULL,
	RUNWITHOWNERCAPS     bit null,
	QUERYMODE            ntext NULL,
	RUNINADVANCEDVIEWER  bit null,
	DSMODE               varchar(4000) null,
	CONSTRAINT PK_CMOBJPROPS51 PRIMARY KEY (CMID) 
)

CREATE TABLE CMOBJPROPS52 (
	CMID             int NOT NULL ,
	CONNECTSTR       nvarchar (1024) NULL ,
	ISOLEVEL         tinyint NULL ,
	QUALIFIER        tinyint NULL ,
	REPLACEMENT      nvarchar (256) NULL ,
	CLOSECONNECTCMD  ntext NULL ,
	OPENCONNECTCMD   ntext NULL ,
	CLOSESESSCMD     ntext NULL ,
	OPENSESSCMD      ntext NULL ,
	APITOKEN         ntext NULL ,
	NOTIFYONCHANGE   bit NULL,
	CONSTRAINT PK_CMOBJPROPS52 PRIMARY KEY (CMID) 
)

CREATE TABLE CMOBJPROPS53 (
	CMID			int NOT NULL ,
	SEQUENCING		tinyint NULL ,
	CONSTRAINT PK_CMOBJPROPS53 PRIMARY KEY (CMID) 
)

CREATE TABLE CMOBJPROPS54 (
	CMID			int NOT NULL ,
	FORMAT			tinyint NULL ,
	OLOCALEID		smallint NULL,
	CONSTRAINT PK_CMOBJPROPS54 PRIMARY KEY (CMID) 
)

CREATE TABLE CMOBJPROPS55 (
	CMID			int NOT NULL ,
	ICONURI			nvarchar (1000) NULL ,
	UCPOLICIES		image NULL, 
	HIDDEN			bit default(0) NOT NULL ,
	CONSTRAINT PK_CMOBJPROPS55 PRIMARY KEY (CMID) 
)
	
CREATE TABLE CMOBJPROPS56 (
	CMID			int NOT NULL ,
	SPEC			ntext NULL ,
	MISSPEC			ntext NULL ,
	CONSTRAINT PK_CMOBJPROPS56 PRIMARY KEY (CMID)
)

CREATE TABLE CMOBJPROPS57 (
	CMID			int NOT NULL ,
	SPEC			ntext NULL ,
 	CONSTRAINT PK_CMOBJPROPS57 PRIMARY KEY (CMID)
)

CREATE TABLE CMOBJPROPS58 (
	CMID			int NOT NULL ,
	PDSELISTAXSCACHE	int NULL,
	PDSSHOWCELLANN		bit NULL,
	PDSMAXPROCS		int NULL,
	PPSHIAFFINECONS		int null,
	PPSAFFINECONS		int null,
	PPSAUDITLEVEL		tinyint null,
	PPSQUEUELIMIT		int null,
	PPSEXECTIMELIMIT	int null,
	BRSPDFCHARENC		tinyint null,
	BRSPDFCOMPRSLVL		int null,
	BRSPDFCOMPRSTYPE	tinyint null,
	BRSPDFEMBEDFONTS	tinyint null,
	RSPDFCHARENC		tinyint null,
	RSPDFCOMPRSLVL		int null,
	RSPDFCOMPRSTYPE		tinyint null,
	RSPDFEMBEDFONTS		tinyint null,
	DMSAFFINECONNECTIONS	int null,
	DMSEXECUTIONTIMELIMIT	int null,
	DMSMAXPROCESSES		int null,
	DMSNONAFFINECONNCTS	int null,
	DMSPEAKMAXPROCESSES	int null,
	DMSPEAKNONAFFINECONNCTS	int null,
	DMSQUEUELIMIT		int null,
	PERDOCVERSRETAGE	varchar (50) null,
	PERDOCVERSRETCOUNT	int NULL,
	EDITION			varchar(20) null,
	EDITIONS		image null,
	DIMSAFFINECONNECTIONS	int null,
    DIMSEXECUTIONTIMELIMIT  int null,
    DIMSMAXPROCESSES        int null,
    DIMSQUEUELIMIT          int null,
	GLOSSARYURI		nvarchar(4000) NULL,
	GSAFFINECONNECTIONS		int null,
	GSEXECUTIONTIMELIMIT	int null,
	GSMAXPROCESSES			int null,
	GSNONAFFINECONNCTS		int null,
	GSPEAKMAXPROCESSES		int null,
	GSPEAKNONAFFINECONNCTS	int null,
	GSQUEUELIMIT			int null,
	GSPEAKCONS			int NULL,
	AASAFFINECONNECTIONS	int null,
	AASEXECUTIONTIMELIMIT   int null,
	AASMAXPROCESSES         int null,
	HTSCOMPTASKLIFE		varchar (50) null,
	CMCSHEAPLIM		integer NULL,
	ANSANNOTATIONLIFE	varchar (50) null,
 	CONSTRAINT PK_CMOBJPROPS58 PRIMARY KEY (CMID)
)

create table CMOBJPROPS59 (
	CMID			int NOT NULL ,
	CONFIGURATION		ntext NULL ,
	USERINTERFACE		tinyint NULL,
 	CONSTRAINT PK_CMOBJPROPS59 PRIMARY KEY (CMID)
)

CREATE TABLE CMOBJPROPS6 (
	CMID			int NOT NULL ,
	URI				nvarchar (4000) NULL ,
	TARGET			nvarchar (4000) NULL ,
	STEPOBJECT		nvarchar (4000) NULL ,
	BASE			nvarchar (4000) NULL ,
	CREDENTIAL		nvarchar (4000) NULL ,
	DISPATCHERPATH	nvarchar (4000) NULL ,
	PAGE			nvarchar (4000) NULL,
	CREDNAMESPACES	nvarchar (4000) null,
	CONSTRAINT PK_CMOBJPROPS6 PRIMARY KEY (CMID) 
)

CREATE TABLE CMOBJPROPS60 (
	CMID			int NOT NULL ,
	CONTEXT         	image NULL,
	CONTEXTCOUNT		int NULL,
	LASTPAGE	nvarchar(256) null,
	CONSTRAINT PK_CMOBJPROPS60 PRIMARY KEY (CMID)
)

CREATE TABLE CMOBJPROPS61 (
	CMID			int NOT NULL ,
	BURSTKEY		nvarchar (4000) NULL,
	CONSTRAINT PK_CMOBJPROPS61 PRIMARY KEY (CMID)
)

CREATE TABLE CMOBJPROPS62 (
	CMID int not null,
	EXPIRATION	datetime null,
	ALLOWANNOTATION		bit null,
	CONSTRAINT PK_CMOBJPROPS62 PRIMARY KEY (CMID)
)

create index IDX_EXPIRATION_62 on CMOBJPROPS62(EXPIRATION)

CREATE TABLE CMOBJPROPS63 (
	CMID			int NOT NULL ,
	SPEC			ntext NULL ,
	CONSTRAINT PK_CMOBJPROPS63 PRIMARY KEY (CMID)
)

CREATE TABLE CMOBJPROPS64 (
	CMID			int NOT NULL ,
	CONTENTTYPE		varchar (256) NULL ,
	DATASIZE		bigint,
	DATACOMP		bit default(0) not null,
	DATAPROP		image NULL, 
	CONSTRAINT PK_CMOBJPROPS64 PRIMARY KEY (CMID)
)

CREATE TABLE CMOBJPROPS65 (
	CMID			int NOT NULL ,
	BURSTID			nvarchar (4000) NULL,
	BURSTIDINDEX	char (44) NULL,
	CONSTRAINT PK_CMOBJPROPS65 PRIMARY KEY (CMID)
)

CREATE INDEX IDX_BURSTIDINDEX ON CMOBJPROPS65(BURSTIDINDEX)

CREATE TABLE CMOBJPROPS66 (
	CMID			int NOT NULL,
	DEFPORTACT		tinyint null,
	SPEC			ntext NULL,
	POWERPLAY8CONFIGURATION ntext NULL,
	CONSTRAINT PK_CMOBJPROPS66 PRIMARY KEY (CMID)
)

CREATE TABLE CMOBJPROPS67 (
	CMID			int NOT NULL,
	NONPEAKDEMANDBGNH	int NULL,
	PEAKDEMANDBEGINH	int NULL,
	ASPEAKCONS		int NULL,
	BRSPEAKAFFINECONS	int NULL,
	BRSPEAKMAXPROCS		int NULL,
	BRSPEAKNONAFFCONS	int NULL,
	CMSPEAKCONS		int NULL,
	DDSPEAKCONS		int NULL,
	DISPEAKCONS		int NULL,
	DMSPEAKCONS		int NULL,
	DSPEAKCONS		int NULL,
	IDSPEAKCONS		int NULL,
	ISSPEAKCONS		int NULL,
	IUSPEAKCONS		int NULL,
	JSPEAKCONS		int NULL,
	MBSPEAKCONS		int NULL,			
	MISPEAKCONS		int NULL,
	MMSPEAKCONS		int NULL,
	PACSPEAKCONS		int NULL,
	PDSPEAKCONS		int NULL,
	PDSPEAKMAXPROCS		int NULL,
	PPSPEAKAFFINECONS	int NULL,
	PPSPEAKNONAFFCONS	int NULL,
	PRSPEAKCONS		int NULL,
	PTSPEAKCONS		int NULL,
	RSPEAKAFFINECONS	int NULL,
	RSPEAKMAXPROCS		int NULL,
	RSPEAKNONAFFCONS	int NULL,
    DIMSNONAFFINECONNCTS	int NULL,
    DIMSPEAKCONS	        int NULL,
    DIMSPEAKMAXPROCS	int NULL,
    DIMSPEAKNONAFFINECONNCTS	int NULL,
	TEMPOBJLOCATION		tinyint NULL,
	TEMPOBJLIFETIME		varchar (50) null,
	AASNONAFFINECONNCTS	int NULL,
	AASPEAKCONS	            int NULL,
	AASPEAKMAXPROCS   	int NULL,
	AASPEAKNONAFFINECONNCTS int NULL,
	STSAFFCONS		int NULL,
	STSEXECLMT		int NULL,
	STSCMAXPROCS		int NULL,
	STSNONAFFCONS		int NULL,
	STSPEAKAFFCONS		int NULL,
	STSPEAKMAXPROCS		int NULL,
	STSPEAKNONAFFCONS	int NULL,	
	OVERRIDEOPTS		ntext NULL,
	SERVRDEFOPTS		ntext NULL,
	STSQUEUELIM			int NULL,
	COLLABDISCURI		nvarchar (4000) NULL, 
	BRSMAXATTACHSIZE	int NULL,
	DSMAXATTACHSIZE		int NULL,
	RSMAXATTACHSIZE		int NULL,
	ASMAXATTACHSIZE		int NULL,
	PPSMAXATTACHSIZE	int NULL,
	QSIDLECONTIMEOUT 	int NULL,
	QSDUMPMODEL 		bit NULL,
	QSDISPLAN 		bit NULL,
	ACTIVEJMXPROXYURI	ntext NULL,
	QSADDJVMARG		nvarchar (1024) NULL,
	QSINITJVMHEAP		int NULL,
	QSMANCUBESTRT		bit NULL,
	QSMAXJVMHEAP		int NULL,
	QSROLAPCUBECONF		image  NULL,
	QSROLAPCADMINCT		int NULL,
	QSRSETQUERYTHRES		int NULL,
	COOKIECAMPASSHTTP		bit NULL,
	CONSTRAINT PK_CMOBJPROPS67 PRIMARY KEY (CMID) 
)

CREATE TABLE CMOBJPROPS68 (
	CMID			int NOT NULL,
	SPEC			ntext NULL,
	CONSTRAINT PK_CMOBJPROPS68 PRIMARY KEY (CMID)
)

CREATE TABLE CMOBJPROPS69 (
	CMID		int NOT NULL,
	ORD		int NOT NULL,
	PARMNAME	nvarchar(256) not null,
	CPARMVALUE	image null,
	constraint PK_CMOBJPROPS69 primary key (CMID, ORD)
)

	
CREATE TABLE CMOBJPROPS7 (
	CMID			int NOT NULL ,
	EXECERROR		ntext NULL ,
	CONFIGURATION	ntext NULL ,
	PORTALPREFS		ntext NULL ,
	CCREDENTIALS	ntext NULL ,
	CMODEL			image NULL ,
	SRC				ntext NULL ,
	SPEC			ntext NULL ,
	STATE			ntext NULL,
	GOVERNORS		ntext null,
	NAMESPFORMAT	nvarchar (4000) null,
	CONSTRAINT PK_CMOBJPROPS7 PRIMARY KEY (CMID) 
)

CREATE TABLE CMOBJPROPS70 (
	CMID            integer not null,
	CONTEXT         ntext NULL,
	DEPLOYREFS	ntext NULL,
	CONSTRAINT PK_CMOBJPROPS70 PRIMARY KEY (CMID)
)

CREATE TABLE CMOBJPROPS71 (
	CMID            integer not null,
	CONTEXT         ntext NULL,
	DEPLOYREFS	ntext NULL,
	CONSTRAINT PK_CMOBJPROPS71 PRIMARY KEY (CMID)
)

CREATE TABLE CMOBJPROPS72 (
	CMID            integer not null,
	CONTEXT         ntext NULL,
	CONSTRAINT PK_CMOBJPROPS72 PRIMARY KEY (CMID)
)

CREATE TABLE CMOBJPROPS73 (
	CMID         integer not null,
	ALIASROOT    nvarchar (256)  NULL,
	URI          nvarchar (4000) NULL,
	UNIXURI      nvarchar (4000) NULL,
	WINDOWSURI   nvarchar (4000) NULL,
	CONSTRAINT PK_CMOBJPROPS73 PRIMARY KEY (CMID)
)

CREATE TABLE CMOBJPROPS74 (
	CMID         	integer not null,
	DEPLOYREFS	ntext NULL,
	LAUNCHTYPE	nvarchar (256) NULL ,
	SPEC		image NULL,
	CONSTRAINT PK_CMOBJPROPS74 PRIMARY KEY (CMID)
)

create index IDX_CMLAUNCHTYPE on CMOBJPROPS74(LAUNCHTYPE)

CREATE TABLE CMOBJPROPS75 (
	CMID         	integer not null,
	RESOURCETYPE	nvarchar (256) NULL ,
	SPEC		image NULL,
	CONSTRAINT PK_CMOBJPROPS75 PRIMARY KEY (CMID)
)

create index IDX_CMRESOURCETYPE on CMOBJPROPS75(RESOURCETYPE)

CREATE TABLE CMOBJPROPS76 (
	CMID         	integer not null,
	CONTENTTYPE	nvarchar (256) NULL ,
	CONSTRAINT PK_CMOBJPROPS76 PRIMARY KEY (CMID)
)

CREATE TABLE CMOBJPROPS77 (
	CMID			 int NOT NULL ,
	DSCONNECTIONNAME nvarchar (256) NULL ,
	DSNAME			 nvarchar (256) NULL ,
	CONSTRAINT PK_CMOBJPROPS77 PRIMARY KEY (CMID) 
)

CREATE TABLE CMOBJPROPS78 (
	CMID         	integer not null,
	BINDINGNAME	nvarchar (256) NULL ,
	INPUTMESSNAME	nvarchar (256) NULL ,
	OPERATIONNAME	nvarchar (256) NULL ,
	OUTPUTMESSNAME	nvarchar (256) NULL ,
	SERVICENAME	nvarchar (256) NULL ,
	BULKEVENTS	bit null,
	URI		ntext NULL,	
	CONSTRAINT PK_CMOBJPROPS78 PRIMARY KEY (CMID)
)

CREATE TABLE CMOBJPROPS79 (
	CMID         	integer not null,
	PUBLISHED	bit null,
	SPEC		ntext null,
	CONSTRAINT PK_CMOBJPROPS79 PRIMARY KEY (CMID)
)

CREATE TABLE CMOBJPROPS80 (
	CMID              int NOT NULL ,
	REPOSITORYRULES   ntext NULL,
	NSCAPS            ntext NULL,
	CONSTRAINT PK_CMOBJPROPS80 PRIMARY KEY (CMID) 
)

CREATE TABLE CMOBJPROPS81 (
	CMID			int NOT NULL ,
	AGGREGATES		ntext NULL,
	CONSTRAINT PK_CMOBJPROPS81 PRIMARY KEY (CMID) 
)

CREATE TABLE CMOBJPROPS82 (
	CMID			int NOT NULL ,
	BPMRESTURI		nvarchar (4000) NULL ,
	CONSTRAINT PK_CMOBJPROPS82 PRIMARY KEY (CMID) 
)

CREATE TABLE CMOBJPROPS83 (
	CMID			int	NOT NULL,
	MOBILECONFIG		image null,
	constraint PK_CMOBJPROPS83 primary key (CMID)
)

CREATE TABLE CMOBJPROPS84 (
	CMID		int NOT NULL ,
	SPEC        ntext NULL,
	DATASIZE	bigint,
	DATAMODTIME	datetime null,
	CONSTRAINT PK_CMOBJPROPS84 PRIMARY KEY (CMID)
)

CREATE TABLE CMOBJPROPS85 (
	CMID             int NOT NULL ,
	DATA             ntext NULL,
	DEPLOYREFS       ntext null,
	OBJREFS          ntext null,
	BIVARS           ntext null,
	EMBEDDING        ntext null,
	STATUS           ntext null,
	USAGETRACKMODEL  ntext null,
	CONSTRAINT PK_CMOBJPROPS85 PRIMARY KEY (CMID) 
)

CREATE TABLE CMOBJPROPS86 (
	CMID			int not null,
	KSCHEMA			nvarchar (256) null,
	KCATALOG		nvarchar (256) null,
	CPHYSDEF		ntext null,
	CPHYSANAL		ntext null,
	CBASEDEF		ntext null,
	CBASEOVER		ntext null,
	CBASEANAL		ntext null,
	STATUSID		tinyint null,
	SNAPSHOT       	ntext null,
	HISTORY       	ntext null,
	SNAPSHOTENBL	bit null,
	DEPLOYREFS		ntext null,
	ALIASROOT		nvarchar (256) null,
	CONSTRAINT PK_CMOBJPROPS86 PRIMARY KEY (CMID) 
)

CREATE TABLE CMOBJPROPS87 (
	CMID        int NOT NULL,
	EXT         ntext NULL,
	CONSTRAINT PK_CMOBJPROPS87 PRIMARY KEY (CMID) 
)

CREATE TABLE CMOBJPROPS88 (
	CMID        int NOT NULL,
	SCHEMATYPE		varchar (256) null,
	STATUS			varchar (256) null,
	STATUSINFO		ntext null,
	CONSTRAINT PK_CMOBJPROPS88 PRIMARY KEY (CMID) 
)

CREATE TABLE CMOBJPROPS89 (
	CMID        int not null,
	DOCTYPE     varchar(64) not null,
	DOCID       varchar(64) not null,
	CONTENT     ntext null,
	CONSTRAINT PK_CMOBJPROPS89 PRIMARY KEY (CMID)
)

create index IDX_CMPROPS89_1 on CMOBJPROPS89(DOCID)

CREATE TABLE CMOBJPROPS9 (
	CMID			int NOT NULL ,
	ASOFTIME		datetime NULL, 
	CANBURST 		bit null,
	CONSTRAINT PK_CMOBJPROPS9 PRIMARY KEY (CMID) 
)

CREATE TABLE CMOBJPROPS90 (
	CMID        int NOT NULL,
	SPEC        ntext NULL,
	CONSTRAINT PK_CMOBJPROPS90 PRIMARY KEY (CMID) 
)

CREATE TABLE CMOBJPROPS91 (
	CMID        int NOT NULL,
	SKDATA      ntext NULL,
	CONSTRAINT PK_CMOBJPROPS91 PRIMARY KEY (CMID) 
)

CREATE TABLE CMOBJPROPS92 (
	CMID        int NOT NULL,
	CONTYPE     varchar(64) NULL,
	URI         ntext NULL,
	SPEC        ntext NULL,
	CONSTRAINT PK_CMOBJPROPS92 PRIMARY KEY (CMID) 
)

CREATE TABLE CMOBJPROPS93 (
	CMID                 int NOT NULL,
	PROGRESS             varchar(1024) NULL,
	JOBID                varchar(64) NULL,
	STATE                varchar(64) NULL,
	CONFIGURATION        ntext NULL,
	CONSTRAINT PK_CMOBJPROPS93 PRIMARY KEY (CMID) 
)

CREATE TABLE CMTAGS (
	CMID      int not null,
	ORD       int not null,
	TAG       nvarchar(256) null,
	constraint PK_CMTAGS primary key (CMID,ORD)
)

create index IDX_CMTAGS on CMTAGS(CMID, TAG)

CREATE TABLE CMPOLICIES (
	CMID			int NOT NULL ,
	POLICIES		image NULL, 
	CONSTRAINT PK_CMPOLICIES PRIMARY KEY (CMID) 
)

CREATE TABLE CMVIEWED (
	CMID			int NOT NULL ,
	OBJID			nvarchar (4000) default ('-') NOT NULL ,
	VIEWED			bit default(0) NOT NULL, 
	CONSTRAINT PK_CMVIEWED PRIMARY KEY (CMID) 
)

CREATE TABLE CMGUIDS (
	CMID			int NOT NULL ,
	GUID			varchar(50) NULL,
	CONSTRAINT PK_CMGUIDS PRIMARY KEY (CMID)
)

create trigger CMGUIDS_INSERT_TR on CMGUIDS
instead of insert
as
begin
	set nocount on
	if	(select count(*) from inserted) <> 0
	begin
		insert into CMGUIDS ( CMID, GUID ) select CMID, newid() from inserted 
	end
end

CREATE TABLE CMPROPERTIES (
	PROPID			smallint NOT NULL,
	NAME			varchar(50) NOT NULL,
	DEF				image		NULL,
	CONSTRAINT PK_CMPROPERTIES PRIMARY KEY(PROPID)
)

CREATE TABLE CMCLASSES (
	CLASSID			int NOT NULL,
	NAME			varchar(50) NOT NULL,
	USAGE			tinyint		NULL,
	DEF				image		NULL,
	CONSTRAINT PK_CMCLASSES PRIMARY KEY(CLASSID)
)

create table CMLOCALES (
	LOCALEID		smallint		not null,
	MAPDLOCALEID	smallint		not null,
	LOCALE			varchar(20)		not null,
	constraint PK_CMLOCALES primary key (LOCALEID)
)

CREATE TABLE  CMREFNOORD1 (
	PROPID		smallint NOT NULL,
	CMID		int NOT NULL,
	REFCMID		int NOT NULL,
	constraint PK_CMREFNOORD1 primary key (CMID, PROPID) )

create index IDX_CMREFNOORD1 on CMREFNOORD1(REFCMID, PROPID)

CREATE TABLE  CMREFORD1 (
	PROPID		smallint NOT NULL,
	CMID		int NOT NULL,
	ORD		int NOT NULL,
	REFCMID		int NOT NULL,
	constraint PK_CMREFORD1 primary key (CMID, PROPID, ORD) )

create index IDX_CMREFORD1 on CMREFORD1(REFCMID, PROPID, ORD)

CREATE TABLE  CMREFORD2 (
	CMID		int NOT NULL,
	ORD		int NOT NULL,
	REFCMID		int NOT NULL,
	constraint PK_CMREFORD2 primary key (CMID,ORD) )

create index IDX_CMREFORD2 on CMREFORD2(REFCMID, ORD)

CREATE TABLE  CMREFNOORD2 (
	CMID		int NOT NULL,
	REFCMID		int NOT NULL,
	constraint PK_CMREFNOORD2 primary key (CMID) )

create index IDX_CMREFNOORD2 on CMREFNOORD2(REFCMID)

CREATE PROCEDURE CMPARSEIDS @QUERYID int, @IDS image AS
SET NOCOUNT ON
DECLARE @IMAGESIZE AS int
DECLARE @CURPOS AS int
SELECT @CURPOS=0
SELECT @IMAGESIZE = DATALENGTH(@IDS)
WHILE @CURPOS < @IMAGESIZE
BEGIN
	INSERT INTO #CMTMPIDS (QUERYID,CMID) SELECT @QUERYID, CAST(SUBSTRING(@IDS, @CURPOS+1, 4) AS int)
	SELECT @CURPOS=@CURPOS+4
END

CREATE PROCEDURE CMPARSECOPYIDS @QUERYID int, @GROUPID int, @SOURCEIDS image, @TARGETIDS image AS
SET NOCOUNT ON
DECLARE @SOURCEIMAGESIZE AS int
DECLARE @CURPOS AS int
SELECT @CURPOS=0
SELECT @SOURCEIMAGESIZE = DATALENGTH(@SOURCEIDS)
WHILE @CURPOS < @SOURCEIMAGESIZE
BEGIN
	INSERT INTO #CMTMPCOPYIDS (QUERYID,GROUPID,SOURCECMID, TARGETCMID) SELECT @QUERYID, @GROUPID,  CAST(SUBSTRING(@SOURCEIDS, @CURPOS+1, 4) AS int), CAST(SUBSTRING(@TARGETIDS, @CURPOS+1, 4) AS int)
	SELECT @CURPOS=@CURPOS+4
END

create view CMOWNERCOUNT(OBJID, OWN_NUMBER) as 
   SELECT p2.OBJID, count(o.CMID)  
   FROM CMOBJECTS o left outer join CMREFNOORD2 p1 on p1.CMID = o.CMID
                    left outer join CMOBJPROPS1 p2 on p1.REFCMID = p2.CMID
   GROUP BY p2.OBJID


CREATE TABLE CMDATAUPGRADE (
	PLUGINNAME 	varchar (255) NOT NULL ,
	VERSION		varchar (64) NULL ,
	CONSTRAINT PK_CMDATAUPGRADE PRIMARY KEY (PLUGINNAME)
)

CREATE TABLE CMSIZEINFO (
	STOREID          varchar(255) NOT NULL,
	CLASSID          int NOT NULL ,
	TOTALFORCLASSID  int NOT NULL ,
	TOTALCOUNT       bigint  NULL ,
	TOTALSIZE        bigint  NULL ,
	CONSTRAINT PK_CMSIZEINFO PRIMARY KEY (STOREID, TOTALFORCLASSID)
)

CREATE TABLE CMSPLIT  (
		CMID		int not null,
		TRANSACTIONID	nvarchar(255),
		constraint PK_CMSPLIT  primary key (CMID, TRANSACTIONID)
)

CREATE TABLE CMDELETEQUEUE (
	OBJID 	 	VARCHAR(255) DEFAULT NULL,
	ITEMID	 	VARCHAR(255) NOT NULL,
	QUEUEID		VARCHAR(255) NOT NULL,
	WORKFLOW 	VARCHAR(255) NOT NULL,
	CONSUMERNAME	VARCHAR(255) DEFAULT NULL,
	STATE		INT NOT NULL,
	INSERTIONTIME 	DATETIME NOT NULL,
	CONSTRAINT PK_CMDELETEQUEUE PRIMARY KEY (ITEMID)
)

CREATE TABLE CMARCHIVEQUEUE (
	OBJID 	 	VARCHAR(255) DEFAULT NULL,
	ITEMID	 	VARCHAR(255) NOT NULL,
	QUEUEID		VARCHAR(255) NOT NULL,
	WORKFLOW 	VARCHAR(255) NOT NULL,
	CONSUMERNAME	VARCHAR(255) DEFAULT NULL,
	STATE		INT NOT NULL,
	INSERTIONTIME 	DATETIME NOT NULL,
	CONSTRAINT PK_CMARCHIVEQUEUE PRIMARY KEY (ITEMID)
)

CREATE TABLE CMINDEXQUEUE (
	OBJID 	 		VARCHAR(1024) DEFAULT NULL,
	ITEMID	 		VARCHAR(50) NOT NULL,
	QUEUEID			VARCHAR(50) NOT NULL,
	WORKFLOW 		VARCHAR(50) NOT NULL,
	CONSUMERNAME	VARCHAR(50) DEFAULT NULL,
	STATE			INT 		NOT NULL,
	INSERTIONTIME 	DATETIME 	NOT NULL,
	INDEXACTION		VARCHAR(50) NOT NULL,
	INDEXCLASS		VARCHAR(255) NOT NULL,
	INDEXPROPS		ntext 		NULL,
	CONSTRAINT PK_CMINDEXQUEUE PRIMARY KEY (ITEMID)
)

create index IDX_CMINDEXQUEUE on CMINDEXQUEUE(STATE, QUEUEID)

CREATE TABLE CMQUEUELOCK (
	QUEUEID		VARCHAR(255) NOT NULL,
	CONSTRAINT PK_CMQUEUELOCK PRIMARY KEY (QUEUEID)
)

CREATE TABLE CMTENANTID (
	TENANTID	INT NOT NULL,
	TENANTNAME	NVARCHAR(255) NOT NULL,
	CONSTRAINT PK_CMTENANTID PRIMARY KEY (TENANTID)
)

INSERT INTO CMTENANTID (TENANTID,TENANTNAME) VALUES (0,'')

INSERT INTO CMSYSPROPS (PROPNAME, PROPVALUE)
	VALUES ('CMStoreVersion', '7.7003')
