CREATE TABLE %%GLOBAL_tablePrefix%%categories (
  categoryid int IDENTITY (1, 1) NOT NULL,
  name varchar(100) NOT NULL DEFAULT (''),
  description varchar(255) NOT NULL DEFAULT (''),
  parentid int NOT NULL DEFAULT (0),
  visits int NOT NULL DEFAULT (0),
  pass varchar(50) NOT NULL DEFAULT (''),
  icon varchar(50) NOT NULL DEFAULT (''),
  security varchar(10) NOT NULL
  check (security  in ('public','private')),
  approvaltype int NOT NULL DEFAULT (0),
  catorder int NOT NULL DEFAULT (0)
);

ALTER TABLE %%GLOBAL_tablePrefix%%categories ADD CONSTRAINT pk_%%GLOBAL_tablePrefix%%_%%GLOBAL_tablePrefix%%_categoryid PRIMARY KEY (categoryid);

CREATE  INDEX %%GLOBAL_tablePrefix%%cat_parentid ON %%GLOBAL_tablePrefix%%categories(parentid);

CREATE  INDEX idx_%%GLOBAL_tablePrefix%%_c_name ON %%GLOBAL_tablePrefix%%categories(name);

CREATE TABLE %%GLOBAL_tablePrefix%%categoryassociations (
  categoryid int NOT NULL DEFAULT(0),
  questionid int NOT NULL DEFAULT(0)
);

ALTER TABLE %%GLOBAL_tablePrefix%%categoryassociations WITH NOCHECK ADD CONSTRAINT idx_%%GLOBAL_tablePrefix%%_a_pk PRIMARY KEY CLUSTERED 
(
	[categoryid],[questionid]
);

CREATE  INDEX idx_%%GLOBAL_tablePrefix%%_ca_categoryquestionids ON %%GLOBAL_tablePrefix%%categoryassociations(questionid,categoryid);

CREATE TABLE %%GLOBAL_tablePrefix%%comments (
  commentid int IDENTITY (1, 1) NOT NULL,
  questionid int NOT NULL DEFAULT(0),
  name varchar(100) NOT NULL DEFAULT(''),
  email varchar(250) NOT NULL DEFAULT(''),
  content text NOT NULL,
  status varchar(15) NOT NULL
  check (status  in ('pending','approved','disapproved')) DEFAULT ('pending'),
  posted datetime NOT NULL
);

ALTER TABLE %%GLOBAL_tablePrefix%%comments ADD CONSTRAINT pk_%%GLOBAL_tablePrefix%%_%%GLOBAL_tablePrefix%%_commentid PRIMARY KEY (commentid);

CREATE  INDEX idx_%%GLOBAL_tablePrefix%%_cm_questionid ON %%GLOBAL_tablePrefix%%comments(questionid);

CREATE  INDEX idx_%%GLOBAL_tablePrefix%%_cm_status ON %%GLOBAL_tablePrefix%%comments(status);

CREATE TABLE %%GLOBAL_tablePrefix%%glossary (
  glossaryid int IDENTITY (1, 1) NOT NULL,
  word varchar(100) NOT NULL DEFAULT(''),
  description text NOT NULL
);

ALTER TABLE %%GLOBAL_tablePrefix%%glossary ADD CONSTRAINT pk_%%GLOBAL_tablePrefix%%_%%GLOBAL_tablePrefix%%_glossaryid PRIMARY KEY (glossaryid);

CREATE  UNIQUE  INDEX idx_%%GLOBAL_tablePrefix%%_g_word ON %%GLOBAL_tablePrefix%%glossary(word);

CREATE TABLE %%GLOBAL_tablePrefix%%groups (
  groupid int IDENTITY (1, 1) NOT NULL,
  name varchar(50) NOT NULL DEFAULT(''),
  permissions text NOT NULL,
  application text NOT NULL,
  contactable tinyint NOT NULL
);

ALTER TABLE %%GLOBAL_tablePrefix%%groups ADD CONSTRAINT pk_%%GLOBAL_tablePrefix%%_%%GLOBAL_tablePrefix%%_groupid PRIMARY KEY (groupid);

CREATE  UNIQUE  INDEX name ON %%GLOBAL_tablePrefix%%groups(name);

CREATE TABLE %%GLOBAL_tablePrefix%%members (
  userid int NOT NULL DEFAULT(0),
  groupid int NOT NULL DEFAULT(0)
);

ALTER TABLE %%GLOBAL_tablePrefix%%members WITH NOCHECK ADD CONSTRAINT idx_%%GLOBAL_tablePrefix%%_members_pk PRIMARY KEY CLUSTERED 
(
	[userid],[groupid]
);

CREATE TABLE %%GLOBAL_tablePrefix%%questions (
  questionid int IDENTITY (1, 1) NOT NULL,
  title varchar(200) NOT NULL DEFAULT(''),
  answer text NOT NULL,
  lastupdated datetime NOT NULL,
  related varchar(100) NOT NULL DEFAULT(''),
  visible tinyint NOT NULL DEFAULT(0),
  sortorder int NOT NULL DEFAULT(0),
  userid int NOT NULL DEFAULT(0),
  views int NOT NULL DEFAULT(0),
  posvotes int NOT NULL DEFAULT(0),
  negvotes int NOT NULL DEFAULT(0),
  score int NOT NULL DEFAULT(0),
  emailed int NOT NULL DEFAULT(0),
  detectrelated tinyint NOT NULL DEFAULT(0),
  metakeywords varchar(255) NOT NULL,
  metadescription text NOT NULL,
  startdate datetime NOT NULL,
  enableexpiry smallint NOT NULL,
  expirydate datetime NOT NULL,
  featured tinyint NOT NULL DEFAULT(0),
  workflowstatus varchar(15) NOT NULL
  check (workflowstatus  in ('auto_approved','pending','re_pending','approved','disapproved')) DEFAULT ('auto_approved')
);

ALTER TABLE %%GLOBAL_tablePrefix%%questions ADD CONSTRAINT pk_%%GLOBAL_tablePrefix%%_%%GLOBAL_tablePrefix%%_questionid PRIMARY KEY (questionid);

CREATE  INDEX idx_%%GLOBAL_tablePrefix%%_q_userid ON %%GLOBAL_tablePrefix%%questions(userid);

CREATE  INDEX idx_%%GLOBAL_tablePrefix%%_q_score ON %%GLOBAL_tablePrefix%%questions(score);

CREATE  INDEX idx_%%GLOBAL_tablePrefix%%_q_lastupdated ON %%GLOBAL_tablePrefix%%questions(lastupdated);

CREATE  INDEX idx_%%GLOBAL_tablePrefix%%_q_title_sortorder ON %%GLOBAL_tablePrefix%%questions(title,sortorder);

CREATE TABLE %%GLOBAL_tablePrefix%%question_auth (
  questionauthid int IDENTITY (1, 1) NOT NULL,
  questionid int NOT NULL,
  groupid int NOT NULL
);

ALTER TABLE %%GLOBAL_tablePrefix%%question_auth ADD CONSTRAINT pk_%%GLOBAL_tablePrefix%%_%%GLOBAL_tablePrefix%%_questionauthid PRIMARY KEY (questionauthid);

CREATE  INDEX groupid ON %%GLOBAL_tablePrefix%%question_auth(groupid);

CREATE  UNIQUE  INDEX questionid ON %%GLOBAL_tablePrefix%%question_auth(questionid,groupid);

CREATE TABLE %%GLOBAL_tablePrefix%%questions_history (
  versionid int IDENTITY (1, 1) NOT NULL,
  questionid int NOT NULL DEFAULT(0),
  title varchar(200) NOT NULL DEFAULT(''),
  answer text NOT NULL,
  lastupdated datetime NOT NULL,
  related varchar(100) NOT NULL DEFAULT(''),
  visible tinyint NOT NULL DEFAULT(0),
  sortorder int NOT NULL DEFAULT(0),
  userid int NOT NULL DEFAULT(0),
  views int NOT NULL DEFAULT(0),
  posvotes int NOT NULL DEFAULT(0),
  negvotes int NOT NULL DEFAULT(0),
  score int NOT NULL DEFAULT(0),
  emailed int NOT NULL DEFAULT(0),
  detectrelated tinyint NOT NULL DEFAULT(0),
  metakeywords varchar(255) NOT NULL,
  metadescription text NOT NULL,
  startdate datetime NOT NULL,
  enableexpiry smallint NOT NULL,
  expirydate datetime NOT NULL,
  featured tinyint NOT NULL DEFAULT(0),
  workflowstatus varchar(15) NOT NULL
  check (workflowstatus  in ('auto_approved','pending','re_pending','approved','disapproved')) DEFAULT ('auto_approved')
);

ALTER TABLE %%GLOBAL_tablePrefix%%questions_history ADD CONSTRAINT pk_%%GLOBAL_tablePrefix%%_%%GLOBAL_tablePrefix%%_versionid PRIMARY KEY (versionid);

CREATE  INDEX questionid ON %%GLOBAL_tablePrefix%%questions_history(questionid);

CREATE  INDEX lastupdated ON %%GLOBAL_tablePrefix%%questions_history(lastupdated);

CREATE TABLE %%GLOBAL_tablePrefix%%ratings (
  rateid int IDENTITY (1, 1) NOT NULL,
  questionid int NOT NULL DEFAULT(0),
  ip varchar(50) NOT NULL DEFAULT(''),
  ratedat datetime NOT NULL,
  ratingemail VARCHAR(60) NOT NULL,
  ratingmessage VARCHAR(250) NOT NULL,
);

ALTER TABLE %%GLOBAL_tablePrefix%%ratings ADD CONSTRAINT pk_%%GLOBAL_tablePrefix%%_%%GLOBAL_tablePrefix%%_rateid PRIMARY KEY (rateid);

CREATE TABLE %%GLOBAL_tablePrefix%%searchhistory (
  searchstring varchar(255) NOT NULL DEFAULT(''),
  amount int NOT NULL DEFAULT(1),
  numresults int NOT NULL DEFAULT(0)
);

ALTER TABLE %%GLOBAL_tablePrefix%%searchhistory ADD CONSTRAINT pk_%%GLOBAL_tablePrefix%%_%%GLOBAL_tablePrefix%%_searchstring PRIMARY KEY (searchstring);

CREATE  INDEX sh_num_res ON %%GLOBAL_tablePrefix%%searchhistory(numresults);

CREATE TABLE %%GLOBAL_tablePrefix%%submittedquestions (
  subquestid int IDENTITY (1, 1) NOT NULL,
  name varchar(100) NOT NULL DEFAULT(''),
  email varchar(250) NOT NULL DEFAULT(''),
  subject varchar(250) NOT NULL DEFAULT(''),
  message text NOT NULL,
  posted datetime NOT NULL
);
ALTER TABLE %%GLOBAL_tablePrefix%%submittedquestions ADD CONSTRAINT pk_%%GLOBAL_tablePrefix%%_%%GLOBAL_tablePrefix%%_subquestid PRIMARY KEY (subquestid);

CREATE TABLE %%GLOBAL_tablePrefix%%subscribers (
  subscriberid int IDENTITY (1, 1) NOT NULL,
  questionid int NOT NULL,
  email varchar(255) NOT NULL,
  subscribedate datetime NOT NULL,
  confirmed tinyint NOT NULL,
  confirmcode varchar(32) NOT NULL
);

ALTER TABLE %%GLOBAL_tablePrefix%%subscribers ADD CONSTRAINT pk_%%GLOBAL_tablePrefix%%_%%GLOBAL_tablePrefix%%_subscriberid PRIMARY KEY (subscriberid);

CREATE  UNIQUE  INDEX idx_%%GLOBAL_tablePrefix%%_s_questionid_email ON %%GLOBAL_tablePrefix%%subscribers(questionid,email);

CREATE  INDEX questionid ON %%GLOBAL_tablePrefix%%subscribers(questionid);

CREATE  INDEX email_confirmcode ON %%GLOBAL_tablePrefix%%subscribers(email,confirmcode);

CREATE TABLE %%GLOBAL_tablePrefix%%users (
  userid int IDENTITY (1, 1) NOT NULL,
  username varchar(50) NOT NULL DEFAULT(''),
  pass varchar(32) NOT NULL DEFAULT(''),
  firstname varchar(50) NOT NULL DEFAULT(''),
  lastname varchar(50) NOT NULL DEFAULT(''),
  status tinyint NOT NULL DEFAULT(0),
  email varchar(255) NOT NULL DEFAULT(''),
  forgotpasscode varchar(32) NOT NULL DEFAULT(''),
  sessionid varchar(32) NOT NULL DEFAULT(''),
  tokencode varchar(128) NOT NULL DEFAULT('')
);

ALTER TABLE %%GLOBAL_tablePrefix%%users ADD CONSTRAINT pk_%%GLOBAL_tablePrefix%%_%%GLOBAL_tablePrefix%%_userid PRIMARY KEY (userid);

CREATE  UNIQUE  INDEX username ON %%GLOBAL_tablePrefix%%users(username);

CREATE  INDEX status ON %%GLOBAL_tablePrefix%%users(status);

CREATE TABLE %%GLOBAL_tablePrefix%%customfields (
  customfieldid int IDENTITY (1, 1) NOT NULL,
  name varchar(100) NOT NULL,
  type varchar(15) NOT NULL
  check (type  in ('multi_check','freeform'))
);

ALTER TABLE %%GLOBAL_tablePrefix%%customfields ADD CONSTRAINT pk_%%GLOBAL_tablePrefix%%_%%GLOBAL_tablePrefix%%_customfieldid PRIMARY KEY (customfieldid);

CREATE TABLE %%GLOBAL_tablePrefix%%customfields_data (
  customfield_dataid int IDENTITY (1, 1) NOT NULL,
  customfieldid int NOT NULL,
  data varchar(250) NOT NULL
);

ALTER TABLE %%GLOBAL_tablePrefix%%customfields_data ADD CONSTRAINT pk_%%GLOBAL_tablePrefix%%_%%GLOBAL_tablePrefix%%_customfield_dataid PRIMARY KEY (customfield_dataid);

CREATE  INDEX customfieldid ON %%GLOBAL_tablePrefix%%customfields_data(customfieldid);

CREATE TABLE %%GLOBAL_tablePrefix%%questions_customfields (
  questions_customfieldsid int IDENTITY (1, 1) NOT NULL,
  questionid int NOT NULL,
  customfieldid int NOT NULL,
  data varchar(250) NOT NULL
);

ALTER TABLE %%GLOBAL_tablePrefix%%questions_customfields ADD CONSTRAINT pk_%%GLOBAL_tablePrefix%%_%%GLOBAL_tablePrefix%%_questions_customfieldsid PRIMARY KEY (questions_customfieldsid);

CREATE  INDEX questionid ON %%GLOBAL_tablePrefix%%questions_customfields(questionid);

CREATE  INDEX customfieldid ON %%GLOBAL_tablePrefix%%questions_customfields(customfieldid);

CREATE TABLE %%GLOBAL_tablePrefix%%newss (
  newsid int IDENTITY (1, 1) NOT NULL,
  title varchar(200) NOT NULL DEFAULT(''),
  content text NOT NULL,
  lastupdated datetime NOT NULL,
  visible tinyint NOT NULL DEFAULT(0),
  userid int NOT NULL DEFAULT(0)
);

ALTER TABLE %%GLOBAL_tablePrefix%%newss ADD CONSTRAINT pk_%%GLOBAL_tablePrefix%%newss PRIMARY KEY (newsid);

CREATE TABLE %%GLOBAL_tablePrefix%%pageindex (
  pageindexid int IDENTITY (1, 1) NOT NULL,
  fullurl varchar(255) NOT NULL,
  questionid int NOT NULL,
  content text NOT NULL,
  plugin varchar(255) NOT NULL,
  filename varchar(255) NOT NULL,
  lastupdated datetime NOT NULL
);

ALTER TABLE %%GLOBAL_tablePrefix%%pageindex ADD CONSTRAINT pk_%%GLOBAL_tablePrefix%%_%%GLOBAL_tablePrefix%%_pageindexid PRIMARY KEY (pageindexid);

CREATE  UNIQUE  INDEX idx_%%GLOBAL_tablePrefix%%_pi_fullurl ON %%GLOBAL_tablePrefix%%pageindex(fullurl);

CREATE  INDEX idx_%%GLOBAL_tablePrefix%%_pi_lastupdated ON %%GLOBAL_tablePrefix%%pageindex(lastupdated);

CREATE TABLE %%GLOBAL_tablePrefix%%userlogin (
  ipaddress varchar(255) NOT NULL,
  attemptnum int NOT NULL,
  tslogin datetime NOT NULL
);

CREATE  UNIQUE  INDEX idx_%%GLOBAL_tablePrefix%%_userlogin_ui_ip ON %%GLOBAL_tablePrefix%%pageindex(ipaddress);


IF FULLTEXTSERVICEPROPERTY ('IsFulltextInstalled') = 1
BEGIN
	EXEC sp_fulltext_database 'enable'
	IF OBJECTPROPERTY ( object_id('%%GLOBAL_tablePrefix%%questions'),
	                    'TableHasActiveFulltextIndex') = 1
	BEGIN
	    EXEC sp_fulltext_table '%%GLOBAL_tablePrefix%%questions', 'drop'
	    EXEC sp_fulltext_catalog '%%GLOBAL_tablePrefix%%Question_FText', 'drop'
	    EXEC sp_fulltext_catalog '%%GLOBAL_tablePrefix%%Question_FText', 'create'
	    EXEC sp_fulltext_table '%%GLOBAL_tablePrefix%%questions', 'create', '%%GLOBAL_tablePrefix%%Question_FText', 'pk_%%GLOBAL_tablePrefix%%_%%GLOBAL_tablePrefix%%_questionid'
	    EXEC sp_fulltext_column '%%GLOBAL_tablePrefix%%questions', 'title', 'add'
	    EXEC sp_fulltext_column '%%GLOBAL_tablePrefix%%questions', 'answer', 'add'
	    EXEC sp_fulltext_column '%%GLOBAL_tablePrefix%%questions', 'metakeywords', 'add'
	    EXEC sp_fulltext_table '%%GLOBAL_tablePrefix%%questions', 'activate'
	END
	ELSE IF OBJECTPROPERTY ( object_id('%%GLOBAL_tablePrefix%%questions'),'TableHasActiveFulltextIndex') = 0
	BEGIN
	    IF FULLTEXTCATALOGPROPERTY ('%%GLOBAL_tablePrefix%%Question_FText', 'PopulateStatus') is null
	    BEGIN
	        EXEC sp_fulltext_catalog '%%GLOBAL_tablePrefix%%Question_FText', 'create'
	    END
	    EXEC sp_fulltext_table '%%GLOBAL_tablePrefix%%questions', 'create', '%%GLOBAL_tablePrefix%%Question_FText', 'pk_%%GLOBAL_tablePrefix%%_%%GLOBAL_tablePrefix%%_questionid'
	    EXEC sp_fulltext_column '%%GLOBAL_tablePrefix%%questions', 'title', 'add'
	    EXEC sp_fulltext_column '%%GLOBAL_tablePrefix%%questions', 'answer', 'add'
	    EXEC sp_fulltext_column '%%GLOBAL_tablePrefix%%questions', 'metakeywords', 'add'
	    EXEC sp_fulltext_table '%%GLOBAL_tablePrefix%%questions', 'activate'
	END
	
	IF OBJECTPROPERTY ( object_id('%%GLOBAL_tablePrefix%%questions_history'),
	                    'TableHasActiveFulltextIndex') = 1
	BEGIN
	    EXEC sp_fulltext_table '%%GLOBAL_tablePrefix%%questions_history', 'drop'
	    EXEC sp_fulltext_catalog '%%GLOBAL_tablePrefix%%QuestionHistory_FText', 'drop'
	    EXEC sp_fulltext_catalog '%%GLOBAL_tablePrefix%%QuestionHistory_FText', 'create'
	    EXEC sp_fulltext_table '%%GLOBAL_tablePrefix%%questions_history', 'create', '%%GLOBAL_tablePrefix%%QuestionHistory_FText', 'pk_%%GLOBAL_tablePrefix%%_%%GLOBAL_tablePrefix%%_versionid'
	    EXEC sp_fulltext_column '%%GLOBAL_tablePrefix%%questions_history', 'title', 'add'
	    EXEC sp_fulltext_column '%%GLOBAL_tablePrefix%%questions_history', 'answer', 'add'
	    EXEC sp_fulltext_column '%%GLOBAL_tablePrefix%%questions_history', 'metakeywords', 'add'
	    EXEC sp_fulltext_table '%%GLOBAL_tablePrefix%%questions_history', 'activate'
	END
	ELSE IF OBJECTPROPERTY ( object_id('%%GLOBAL_tablePrefix%%questions_history'),'TableHasActiveFulltextIndex') = 0
	BEGIN
	    IF FULLTEXTCATALOGPROPERTY ('%%GLOBAL_tablePrefix%%QuestionHistory_FText', 'PopulateStatus') is null
	    BEGIN
	        EXEC sp_fulltext_catalog '%%GLOBAL_tablePrefix%%QuestionHistory_FText', 'create'
	    END
	    EXEC sp_fulltext_table '%%GLOBAL_tablePrefix%%questions_history', 'create', '%%GLOBAL_tablePrefix%%Question_FText', 'pk_%%GLOBAL_tablePrefix%%_%%GLOBAL_tablePrefix%%_versionid'
	    EXEC sp_fulltext_column '%%GLOBAL_tablePrefix%%questions_history', 'title', 'add'
	    EXEC sp_fulltext_column '%%GLOBAL_tablePrefix%%questions_history', 'answer', 'add'
	    EXEC sp_fulltext_column '%%GLOBAL_tablePrefix%%questions_history', 'metakeywords', 'add'
	    EXEC sp_fulltext_table '%%GLOBAL_tablePrefix%%questions_history', 'activate'
	END
	
	IF OBJECTPROPERTY ( object_id('%%GLOBAL_tablePrefix%%searchhistory'),
	                    'TableHasActiveFulltextIndex') = 1
	BEGIN
	    EXEC sp_fulltext_table '%%GLOBAL_tablePrefix%%searchhistory', 'drop'
	    EXEC sp_fulltext_catalog '%%GLOBAL_tablePrefix%%SearchHistory_FText', 'drop'
	    EXEC sp_fulltext_catalog '%%GLOBAL_tablePrefix%%SearchHistory_FText', 'create'
	    EXEC sp_fulltext_table '%%GLOBAL_tablePrefix%%searchhistory', 'create', '%%GLOBAL_tablePrefix%%SearchHistory_FText', 'pk_%%GLOBAL_tablePrefix%%_%%GLOBAL_tablePrefix%%_searchstring'
	    EXEC sp_fulltext_column '%%GLOBAL_tablePrefix%%searchhistory', 'searchstring', 'add'
	    EXEC sp_fulltext_table '%%GLOBAL_tablePrefix%%searchhistory', 'activate'
	END
	ELSE IF OBJECTPROPERTY ( object_id('%%GLOBAL_tablePrefix%%searchhistory'),'TableHasActiveFulltextIndex') = 0
	BEGIN
	    IF FULLTEXTCATALOGPROPERTY ('%%GLOBAL_tablePrefix%%SearchHistory_FText', 'PopulateStatus') is null
	    BEGIN
	        EXEC sp_fulltext_catalog '%%GLOBAL_tablePrefix%%SearchHistory_FText', 'create'
	    END
	    EXEC sp_fulltext_table '%%GLOBAL_tablePrefix%%searchhistory', 'create', '%%GLOBAL_tablePrefix%%SearchHistory_FText', 'pk_%%GLOBAL_tablePrefix%%_%%GLOBAL_tablePrefix%%_searchstring'
	    EXEC sp_fulltext_column '%%GLOBAL_tablePrefix%%searchhistory', 'searchstring', 'add'
	    EXEC sp_fulltext_table '%%GLOBAL_tablePrefix%%searchhistory', 'activate'
	END
	
	IF OBJECTPROPERTY ( object_id('%%GLOBAL_tablePrefix%%pageindex'),
	                    'TableHasActiveFulltextIndex') = 1
	BEGIN
	    EXEC sp_fulltext_table '%%GLOBAL_tablePrefix%%pageindex', 'drop'
	    EXEC sp_fulltext_catalog '%%GLOBAL_tablePrefix%%PageIndex_FText', 'drop'
	    EXEC sp_fulltext_catalog '%%GLOBAL_tablePrefix%%PageIndex_FText', 'create'
	    EXEC sp_fulltext_table '%%GLOBAL_tablePrefix%%pageindex', 'create', '%%GLOBAL_tablePrefix%%PageIndex_FText', 'pk_%%GLOBAL_tablePrefix%%_%%GLOBAL_tablePrefix%%_pageindexid'
	    EXEC sp_fulltext_column '%%GLOBAL_tablePrefix%%pageindex', 'content', 'add'
	    EXEC sp_fulltext_column '%%GLOBAL_tablePrefix%%pageindex', 'filename', 'add'
	    EXEC sp_fulltext_table '%%GLOBAL_tablePrefix%%pageindex', 'activate'
	END
	ELSE IF OBJECTPROPERTY ( object_id('%%GLOBAL_tablePrefix%%pageindex'),'TableHasActiveFulltextIndex') = 0
	BEGIN
	    IF FULLTEXTCATALOGPROPERTY ('%%GLOBAL_tablePrefix%%PageIndex_FText', 'PopulateStatus') is null
	    BEGIN
	        EXEC sp_fulltext_catalog '%%GLOBAL_tablePrefix%%PageIndex_FText', 'create'
	    END
	    EXEC sp_fulltext_table '%%GLOBAL_tablePrefix%%pageindex', 'create', '%%GLOBAL_tablePrefix%%PageIndex_FText', 'pk_%%GLOBAL_tablePrefix%%_%%GLOBAL_tablePrefix%%_pageindexid'
	    EXEC sp_fulltext_column '%%GLOBAL_tablePrefix%%pageindex', 'content', 'add'
	    EXEC sp_fulltext_column '%%GLOBAL_tablePrefix%%pageindex', 'filename', 'add'
	    EXEC sp_fulltext_table '%%GLOBAL_tablePrefix%%pageindex', 'activate'
	END
	EXEC sp_fulltext_table '%%GLOBAL_tablePrefix%%searchhistory', 'start_full'
	EXEC sp_fulltext_table '%%GLOBAL_tablePrefix%%pageindex', 'start_full'
	EXEC sp_fulltext_table '%%GLOBAL_tablePrefix%%questions', 'start_full'
END;

IF OBJECTPROPERTY ( object_id('%%GLOBAL_tablePrefix%%categories'),'TableHasIdentity') = 1 BEGIN SET IDENTITY_INSERT %%GLOBAL_tablePrefix%%categories OFF END;

IF OBJECTPROPERTY ( object_id('%%GLOBAL_tablePrefix%%categoryassociations'),'TableHasIdentity') = 1 BEGIN SET IDENTITY_INSERT %%GLOBAL_tablePrefix%%categoryassociations OFF END;

IF OBJECTPROPERTY ( object_id('%%GLOBAL_tablePrefix%%comments'),'TableHasIdentity') = 1 BEGIN SET IDENTITY_INSERT %%GLOBAL_tablePrefix%%comments OFF END;

IF OBJECTPROPERTY ( object_id('%%GLOBAL_tablePrefix%%glossary'),'TableHasIdentity') = 1 BEGIN SET IDENTITY_INSERT %%GLOBAL_tablePrefix%%glossary OFF END;

IF OBJECTPROPERTY ( object_id('%%GLOBAL_tablePrefix%%groups'),'TableHasIdentity') = 1 BEGIN SET IDENTITY_INSERT %%GLOBAL_tablePrefix%%groups OFF END;

IF OBJECTPROPERTY ( object_id('%%GLOBAL_tablePrefix%%members'),'TableHasIdentity') = 1 BEGIN SET IDENTITY_INSERT %%GLOBAL_tablePrefix%%members OFF END;

IF OBJECTPROPERTY ( object_id('%%GLOBAL_tablePrefix%%questions'),'TableHasIdentity') = 1 BEGIN SET IDENTITY_INSERT %%GLOBAL_tablePrefix%%questions OFF END;

IF OBJECTPROPERTY ( object_id('%%GLOBAL_tablePrefix%%questions_history'),'TableHasIdentity') = 1 BEGIN SET IDENTITY_INSERT %%GLOBAL_tablePrefix%%questions_history OFF END;

IF OBJECTPROPERTY ( object_id('%%GLOBAL_tablePrefix%%question_auth'),'TableHasIdentity') = 1 BEGIN SET IDENTITY_INSERT %%GLOBAL_tablePrefix%%question_auth OFF END;

IF OBJECTPROPERTY ( object_id('%%GLOBAL_tablePrefix%%questions_customfields'),'TableHasIdentity') = 1 BEGIN SET IDENTITY_INSERT %%GLOBAL_tablePrefix%%questions_customfields OFF END;

IF OBJECTPROPERTY ( object_id('%%GLOBAL_tablePrefix%%ratings'),'TableHasIdentity') = 1 BEGIN SET IDENTITY_INSERT %%GLOBAL_tablePrefix%%ratings OFF END;

IF OBJECTPROPERTY ( object_id('%%GLOBAL_tablePrefix%%searchhistory'),'TableHasIdentity') = 1 BEGIN SET IDENTITY_INSERT %%GLOBAL_tablePrefix%%searchhistory OFF END;

IF OBJECTPROPERTY ( object_id('%%GLOBAL_tablePrefix%%submittedquestions'),'TableHasIdentity') = 1 BEGIN SET IDENTITY_INSERT %%GLOBAL_tablePrefix%%submittedquestions OFF END;

IF OBJECTPROPERTY ( object_id('%%GLOBAL_tablePrefix%%subscribers'),'TableHasIdentity') = 1 BEGIN SET IDENTITY_INSERT %%GLOBAL_tablePrefix%%subscribers OFF END;

IF OBJECTPROPERTY ( object_id('%%GLOBAL_tablePrefix%%users'),'TableHasIdentity') = 1 BEGIN SET IDENTITY_INSERT %%GLOBAL_tablePrefix%%users OFF END;

IF OBJECTPROPERTY ( object_id('%%GLOBAL_tablePrefix%%customfields'),'TableHasIdentity') = 1 BEGIN SET IDENTITY_INSERT %%GLOBAL_tablePrefix%%customfields OFF END;

IF OBJECTPROPERTY ( object_id('%%GLOBAL_tablePrefix%%customfields_data'),'TableHasIdentity') = 1 BEGIN SET IDENTITY_INSERT %%GLOBAL_tablePrefix%%customfields_data OFF END;

IF OBJECTPROPERTY ( object_id('%%GLOBAL_tablePrefix%%newss'),'TableHasIdentity') = 1 BEGIN SET IDENTITY_INSERT %%GLOBAL_tablePrefix%%newss OFF END;

IF OBJECTPROPERTY ( object_id('%%GLOBAL_tablePrefix%%pageindex'),'TableHasIdentity') = 1 BEGIN SET IDENTITY_INSERT %%GLOBAL_tablePrefix%%pageindex OFF END;
