CREATE TABLE TBIDB_BASE
(
	GUID			INTEGER			NOT NULL	IDENTITY (1, 1),
	CONFIG_NAME		VARCHAR(900)	NOT NULL,
	CONFIG_VALUE	VARCHAR(MAX)	NOT NULL,
	COMMENT			VARCHAR(500),
	ADDED_WHO	    VARCHAR(30)     NOT NULL    DEFAULT 'Digital Data',
	ADDED_WHEN   	DATETIME 	    NOT NULL 	DEFAULT (GETDATE()),
	CHANGED_WHO     VARCHAR(30),
	CHANGED_WHEN	DATETIME,
	CONSTRAINT PK_TBIDB_BASE 	   PRIMARY KEY (GUID),
	CONSTRAINT UQ1_TBIDB_BASE	   UNIQUE (CONFIG_NAME)
)
GO
CREATE TRIGGER TBIDB_BASE_AFT_UPD ON TBIDB_BASE
FOR UPDATE
AS
  UPDATE TBIDB_BASE SET CHANGED_WHEN = GETDATE()
  FROM INSERTED
  WHERE TBIDB_BASE.GUID = INSERTED.GUID
GO
INSERT INTO TBIDB_BASE (CONFIG_NAME,CONFIG_VALUE) VALUES ('DB_VERSION','1.0.1')
GO
ALTER TABLE TBIDB_OBJECT_STORE ADD IS_ARCHIVE BIT NOT NULL DEFAULT 0
GO 
CREATE VIEW VWIDB_OBJECTSTORE AS
SELECT 
	T.GUID As OST_ID,
	T.OBJECT_TITLE AS OS_TITLE,
	T.IS_ARCHIVE AS OS_IS_ARCHIVE,
	T1.CAT_STRING AS IDB_PRAEFIX
FROM
TBIDB_OBJECT_STORE T 
	INNER JOIN TBIDB_CATALOG T1 ON T.CAT_ID = T1.GUID
GO