USE [master]
GO
/****** Object:  Database [{DBName}]    Script Date: 01/06/2012 15:49:32 ******/
IF  EXISTS (SELECT name FROM sys.databases WHERE name = N'{DBName}')
BEGIN
	PRINT 'Dropping existing database {DBName}'
	ALTER DATABASE [{DBName}] SET SINGLE_USER WITH ROLLBACK IMMEDIATE
	DROP DATABASE [{DBName}]
END
GO
/****** Object:  Database [{DBName}]    Script Date: 01/06/2012 15:02:52 ******/
PRINT 'Creating Database {DBName} - {DBPath}\{DBName}.mdf'
GO
CREATE DATABASE [{DBName}] ON  PRIMARY 
( NAME = N'VEPROMS_Users', FILENAME = N'{DBPath}\{DBName}.mdf')
 LOG ON 
( NAME = N'VEPROMS_Users_log', FILENAME = N'{DBPath}\{DBName}_1.ldf')
 COLLATE SQL_Latin1_General_CP1_CI_AS
GO
PRINT '{DBName} Created'
GO
EXEC dbo.sp_dbcmptlevel @dbname=N'{DBName}', @new_cmptlevel=90
GO
PRINT '{sp_dbcmptlevel} Completed'
GO
IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
begin
EXEC [{DBName}].[dbo].[sp_fulltext_database] @action = 'disable'
end
GO
ALTER DATABASE [{DBName}] SET ANSI_NULL_DEFAULT OFF
GO
ALTER DATABASE [{DBName}] SET ANSI_NULLS OFF
GO
ALTER DATABASE [{DBName}] SET ANSI_PADDING OFF
GO
ALTER DATABASE [{DBName}] SET ANSI_WARNINGS OFF
GO
ALTER DATABASE [{DBName}] SET ARITHABORT OFF
GO
ALTER DATABASE [{DBName}] SET AUTO_CLOSE OFF
GO
ALTER DATABASE [{DBName}] SET AUTO_CREATE_STATISTICS ON
GO
ALTER DATABASE [{DBName}] SET AUTO_SHRINK OFF
GO
ALTER DATABASE [{DBName}] SET AUTO_UPDATE_STATISTICS ON
GO
ALTER DATABASE [{DBName}] SET CURSOR_CLOSE_ON_COMMIT OFF
GO
ALTER DATABASE [{DBName}] SET CURSOR_DEFAULT  GLOBAL
GO
ALTER DATABASE [{DBName}] SET CONCAT_NULL_YIELDS_NULL OFF
GO
ALTER DATABASE [{DBName}] SET NUMERIC_ROUNDABORT OFF
GO
ALTER DATABASE [{DBName}] SET QUOTED_IDENTIFIER OFF
GO
ALTER DATABASE [{DBName}] SET RECURSIVE_TRIGGERS OFF
GO
ALTER DATABASE [{DBName}] SET  DISABLE_BROKER
GO
ALTER DATABASE [{DBName}] SET AUTO_UPDATE_STATISTICS_ASYNC OFF
GO
ALTER DATABASE [{DBName}] SET DATE_CORRELATION_OPTIMIZATION OFF
GO
ALTER DATABASE [{DBName}] SET TRUSTWORTHY OFF
GO
ALTER DATABASE [{DBName}] SET ALLOW_SNAPSHOT_ISOLATION OFF
GO
ALTER DATABASE [{DBName}] SET PARAMETERIZATION SIMPLE
GO
ALTER DATABASE [{DBName}] SET  READ_WRITE
GO
ALTER DATABASE [{DBName}] SET RECOVERY SIMPLE
GO
ALTER DATABASE [{DBName}] SET  MULTI_USER
GO
ALTER DATABASE [{DBName}] SET PAGE_VERIFY CHECKSUM
GO
ALTER DATABASE [{DBName}] SET DB_CHAINING OFF
GO
USE [{DBName}]
GO


/****** Object:  Table [dbo].[Connections]    Script Date: 01/06/2012 15:02:52 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [Connections](
	[DBID] [int] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Title] [nvarchar](510) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[ConnectionString] [nvarchar](510) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[ServerType] [int] NOT NULL CONSTRAINT [DF_Connections_ServerType]  DEFAULT ((1)),
	[Config] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[DTS] [datetime] NOT NULL CONSTRAINT [DF_Connections_DTS]  DEFAULT (getdate()),
	[UsrID] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_Connections_UserID]  DEFAULT (upper(suser_sname())),
	[LastChanged] [timestamp] NOT NULL,
 CONSTRAINT [PK_Connections] PRIMARY KEY CLUSTERED 
(
	[DBID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
CREATE UNIQUE NONCLUSTERED INDEX [IX_Connections] ON [Connections] 
(
	[Name] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'0 SQL Server' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Connections', @level2type=N'COLUMN',@level2name=N'ServerType'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'{datetime}' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Connections', @level2type=N'COLUMN',@level2name=N'DTS'
GO
/****** Object:  Table [dbo].[RODbs]    Script Date: 01/06/2012 15:02:52 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [RODbs](
	[RODbID] [int] IDENTITY(1,1) NOT NULL,
	[ROName] [nvarchar](255) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
	[FolderPath] [nvarchar](255) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
	[DBConnectionString] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
	[Config] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[DTS] [datetime] NOT NULL CONSTRAINT [DF_RODbs_DTS]  DEFAULT (getdate()),
	[UserID] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_RODbs_UserID]  DEFAULT (upper(suser_sname())),
	[LastChanged] [timestamp] NOT NULL,
 CONSTRAINT [PK_RODbs] PRIMARY KEY CLUSTERED 
(
	[RODbID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
CREATE UNIQUE NONCLUSTERED INDEX [IX_RODbs_FolderPath] ON [RODbs] 
(
	[FolderPath] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Hook for future - to allow the user to select multiple RO Databases assocaiated with on DocVersion' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'RODbs', @level2type=N'COLUMN',@level2name=N'ROName'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Path to the RO database' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'RODbs', @level2type=N'COLUMN',@level2name=N'FolderPath'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Connection String - Default could just be the full path and name of the database' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'RODbs', @level2type=N'COLUMN',@level2name=N'DBConnectionString'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'{datetime}' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'RODbs', @level2type=N'COLUMN',@level2name=N'DTS'
GO
/****** Object:  Table [dbo].[Locks]    Script Date: 01/06/2012 15:02:52 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [Locks](
	[LockID] [int] IDENTITY(1,1) NOT NULL,
	[UserID] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_Locks_UserID]  DEFAULT (upper(suser_sname())),
	[LockType] [tinyint] NOT NULL CONSTRAINT [DF_Locks_LockType]  DEFAULT ((0)),
	[LockItemID] [int] NOT NULL CONSTRAINT [DF_Locks_LockItemID]  DEFAULT ((0)),
	[Description] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[DTS] [datetime] NOT NULL CONSTRAINT [DF_Locks_DTS]  DEFAULT (getdate()),
	[LastChanged] [timestamp] NOT NULL,
 CONSTRAINT [PK_Locks] PRIMARY KEY CLUSTERED 
(
	[LockID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'{datetime}' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Locks', @level2type=N'COLUMN',@level2name=N'DTS'
GO
/****** Object:  Table [dbo].[Documents]    Script Date: 01/06/2012 15:02:52 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [Documents](
	[DocID] [int] IDENTITY(1,1) NOT NULL,
	[LibTitle] [nvarchar](1024) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[DocContent] [varbinary](max) NULL,
	[DocAscii] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Config] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[DTS] [datetime] NOT NULL CONSTRAINT [DF_Documents_DTS]  DEFAULT (getdate()),
	[UserID] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_Documents_UserID]  DEFAULT (upper(suser_sname())),
	[LastChanged] [timestamp] NOT NULL,
	[FileExtension] [nvarchar](10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_Documents_FileExtension]  DEFAULT (N'.Doc'),
 CONSTRAINT [PK_Documents] PRIMARY KEY CLUSTERED 
(
	[DocID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Actual content of a Word Document (RTF, DOC or XML Format)' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Documents', @level2type=N'COLUMN',@level2name=N'DocContent'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Used for searching' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Documents', @level2type=N'COLUMN',@level2name=N'DocAscii'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'{datetime}' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Documents', @level2type=N'COLUMN',@level2name=N'DTS'
GO
/****** Object:  Table [dbo].[Groups]    Script Date: 01/06/2012 15:02:52 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [Groups](
	[GID] [int] IDENTITY(1,1) NOT NULL,
	[GroupName] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
	[GroupType] [int] NULL,
	[Config] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[DTS] [datetime] NOT NULL CONSTRAINT [DF_Groups_DTS]  DEFAULT (getdate()),
	[UsrID] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_Groups_UserID]  DEFAULT (upper(suser_sname())),
	[LastChanged] [timestamp] NOT NULL,
 CONSTRAINT [PK_Groups] PRIMARY KEY CLUSTERED 
(
	[GID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
CREATE UNIQUE NONCLUSTERED INDEX [IX_Groups] ON [Groups] 
(
	[GroupName] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'{datetime}' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Groups', @level2type=N'COLUMN',@level2name=N'GID'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'{datetime}' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Groups', @level2type=N'COLUMN',@level2name=N'DTS'
GO
/****** Object:  Table [dbo].[Users]    Script Date: 01/06/2012 15:02:52 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [Users](
	[UID] [int] IDENTITY(1,1) NOT NULL,
	[UserID] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_Users_UserID]  DEFAULT (upper(suser_sname())),
	[FirstName] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[MiddleName] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[LastName] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Suffix] [nvarchar](10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[CourtesyTitle] [nvarchar](10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[PhoneNumber] [nvarchar](30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[CFGName] [nvarchar](8) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[UserLogin] [nvarchar](10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[UserName] [nvarchar](32) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Config] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[DTS] [datetime] NOT NULL CONSTRAINT [DF_Users_DTS]  DEFAULT (getdate()),
	[UsrID] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_Users_UserID1]  DEFAULT (upper(suser_sname())),
	[LastChanged] [timestamp] NOT NULL,
 CONSTRAINT [PK_Users] PRIMARY KEY CLUSTERED 
(
	[UID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'{datetime}' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Users', @level2type=N'COLUMN',@level2name=N'DTS'
GO
/****** Object:  Table [dbo].[Formats]    Script Date: 01/06/2012 15:02:52 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [Formats](
	[FormatID] [int] IDENTITY(1,1) NOT NULL,
	[ParentID] [int] NOT NULL CONSTRAINT [DF_Formats_ParentID]  DEFAULT ((1)),
	[Name] [nvarchar](20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
	[Description] [nvarchar](250) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Data] [xml] NOT NULL,
	[GenMac] [xml] NULL,
	[DTS] [datetime] NOT NULL CONSTRAINT [DF_Formats_DTS]  DEFAULT (getdate()),
	[UserID] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_Formats_UserID]  DEFAULT (upper(suser_sname())),
	[LastChanged] [timestamp] NOT NULL,
 CONSTRAINT [PK_Formats] PRIMARY KEY CLUSTERED 
(
	[FormatID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
CREATE UNIQUE NONCLUSTERED INDEX [IX_Formats] ON [Formats] 
(
	[ParentID] ASC,
	[Name] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_FormatsParentID] ON [Formats] 
(
	[ParentID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'{datetime}' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Formats', @level2type=N'COLUMN',@level2name=N'DTS'
GO
/****** Object:  Table [dbo].[Sessions]    Script Date: 01/06/2012 15:02:52 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [Sessions](
	[SessionID] [int] IDENTITY(1,1) NOT NULL,
	[UserID] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_Sessions_UserID]  DEFAULT (upper(suser_sname())),
	[DTSDtart] [datetime] NOT NULL CONSTRAINT [DF_Sessions_DTSDtart]  DEFAULT (getdate()),
	[DTSEnd] [datetime] NULL,
	[DTSActivity] [datetime] NULL,
	[LastChanged] [timestamp] NOT NULL,
 CONSTRAINT [PK_Sessions] PRIMARY KEY CLUSTERED 
(
	[SessionID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'{datetime}' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Sessions', @level2type=N'COLUMN',@level2name=N'DTSDtart'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'{datetime}' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Sessions', @level2type=N'COLUMN',@level2name=N'DTSEnd'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'{datetime}' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Sessions', @level2type=N'COLUMN',@level2name=N'DTSActivity'
GO
/****** Object:  Table [dbo].[Branches]    Script Date: 01/06/2012 15:02:52 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [Branches](
	[BranchID] [int] IDENTITY(1,1) NOT NULL,
	[VersionID] [int] NOT NULL CONSTRAINT [DF_Branches_VersionID]  DEFAULT ((0)),
	[DateLimit] [datetime] NOT NULL CONSTRAINT [DF_Branches_DateLimit]  DEFAULT (getdate()),
	[BeforeType] [tinyint] NOT NULL CONSTRAINT [DF_Branches_BeforeType]  DEFAULT ((0)),
	[BeforeID] [int] NOT NULL CONSTRAINT [DF_Branches_BeforeID]  DEFAULT ((0)),
	[AfterType] [tinyint] NOT NULL CONSTRAINT [DF_Branches_AfterType]  DEFAULT ((0)),
	[AfterID] [int] NOT NULL CONSTRAINT [DF_Branches_AfterID]  DEFAULT ((0)),
	[LastChanged] [timestamp] NOT NULL,
 CONSTRAINT [PK_Branches] PRIMARY KEY CLUSTERED 
(
	[BranchID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'{datetime}' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Branches', @level2type=N'COLUMN',@level2name=N'DateLimit'
GO
/****** Object:  Table [dbo].[AnnotationTypes]    Script Date: 01/06/2012 15:02:52 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [AnnotationTypes](
	[TypeID] [int] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
	[Config] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[DTS] [datetime] NOT NULL CONSTRAINT [DF_AnnotationTypes_DTS]  DEFAULT (getdate()),
	[UserID] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_AnnotationTypes_UserID]  DEFAULT (upper(suser_sname())),
	[LastChanged] [timestamp] NOT NULL,
 CONSTRAINT [PK_AnnotationTypes] PRIMARY KEY CLUSTERED 
(
	[TypeID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
CREATE UNIQUE NONCLUSTERED INDEX [IX_AnnotationTypes_Name] ON [AnnotationTypes] 
(
	[Name] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'{datetime}' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'AnnotationTypes', @level2type=N'COLUMN',@level2name=N'DTS'
GO
/****** Object:  Table [dbo].[Owners]    Script Date: 01/06/2012 15:02:52 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [Owners](
	[OwnerID] [int] IDENTITY(1,1) NOT NULL,
	[SessionID] [int] NOT NULL CONSTRAINT [DF_Owners_SessionID]  DEFAULT ((0)),
	[OwnerType] [tinyint] NOT NULL CONSTRAINT [DF_Owners_OwnerType]  DEFAULT ((0)),
	[OwnerItemID] [int] NOT NULL CONSTRAINT [DF_Owners_OwnerItemID]  DEFAULT ((0)),
	[DTSStart] [datetime] NOT NULL CONSTRAINT [DF_Owners_DTSStart]  DEFAULT (getdate()),
	[LastChanged] [timestamp] NOT NULL,
 CONSTRAINT [PK_Owners] PRIMARY KEY CLUSTERED 
(
	[OwnerID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'{datetime}' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Owners', @level2type=N'COLUMN',@level2name=N'DTSStart'
GO
/****** Object:  Table [dbo].[ApplicableStructures]    Script Date: 01/06/2012 15:02:52 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [ApplicableStructures](
	[StructureID] [int] NOT NULL,
	[AppItems] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[DTS] [datetime] NOT NULL CONSTRAINT [DF_ApplicableStructures_DTS]  DEFAULT (getdate()),
	[UserID] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_ApplicableStructures_UserID]  DEFAULT (upper(suser_sname())),
	[LastChanged] [timestamp] NOT NULL,
 CONSTRAINT [PK_ApplicableStructures] PRIMARY KEY CLUSTERED 
(
	[StructureID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'A series of characters - Y means Applicable, N means Not Applicable, Space means undecided' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'ApplicableStructures', @level2type=N'COLUMN',@level2name=N'AppItems'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'{datetime}' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'ApplicableStructures', @level2type=N'COLUMN',@level2name=N'DTS'
GO
/****** Object:  Table [dbo].[Roles]    Script Date: 01/06/2012 15:02:52 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [Roles](
	[RID] [int] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
	[Title] [nvarchar](250) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
	[DTS] [datetime] NOT NULL CONSTRAINT [DF_Roles_DTS]  DEFAULT (getdate()),
	[UsrID] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_Roles_UsrID]  DEFAULT (upper(suser_sname())),
	[LastChanged] [timestamp] NOT NULL,
 CONSTRAINT [PK_Roles] PRIMARY KEY CLUSTERED 
(
	[RID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
CREATE UNIQUE NONCLUSTERED INDEX [IX_Roles] ON [Roles] 
(
	[Name] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'{datetime}' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Roles', @level2type=N'COLUMN',@level2name=N'DTS'
GO
/****** Object:  Table [dbo].[Associations]    Script Date: 01/06/2012 15:02:52 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [Associations](
	[AssociationID] [int] IDENTITY(1,1) NOT NULL,
	[VersionID] [int] NOT NULL,
	[ROFstID] [int] NOT NULL,
	[Config] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[DTS] [datetime] NOT NULL CONSTRAINT [DF_Associations_DTS]  DEFAULT (getdate()),
	[UserID] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_Associations_UserID]  DEFAULT (upper(suser_sname())),
	[LastChanged] [timestamp] NOT NULL,
 CONSTRAINT [PK_Associations_1] PRIMARY KEY CLUSTERED 
(
	[AssociationID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
CREATE UNIQUE NONCLUSTERED INDEX [IX_Associations_VersionID_ROFstID] ON [Associations] 
(
	[VersionID] ASC,
	[ROFstID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'{datetime}' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Associations', @level2type=N'COLUMN',@level2name=N'DTS'
GO
/****** Object:  Table [dbo].[Folders]    Script Date: 01/06/2012 15:02:52 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [Folders](
	[FolderID] [int] IDENTITY(1,1) NOT NULL,
	[ParentID] [int] NOT NULL CONSTRAINT [DF_Folders_ParentID]  DEFAULT ((1)),
	[DBID] [int] NOT NULL CONSTRAINT [DF_DataSets_DBID]  DEFAULT ((1)),
	[Name] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
	[Title] [nvarchar](510) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[ShortName] [nvarchar](20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
	[FormatID] [int] NULL,
	[ManualOrder] [float] NULL,
	[Config] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[DTS] [datetime] NOT NULL CONSTRAINT [DF_DataSets_DTS]  DEFAULT (getdate()),
	[UsrID] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_DataSets_UserID]  DEFAULT (upper(suser_sname())),
	[LastChanged] [timestamp] NOT NULL,
 CONSTRAINT [PK_DataSets] PRIMARY KEY CLUSTERED 
(
	[FolderID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_FoldersDBID] ON [Folders] 
(
	[DBID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_FoldersFormatID] ON [Folders] 
(
	[FormatID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_FoldersParentID] ON [Folders] 
(
	[ParentID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
CREATE UNIQUE NONCLUSTERED INDEX [IX_UniqueChildFolders] ON [Folders] 
(
	[ParentID] ASC,
	[Name] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'{datetime}' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Folders', @level2type=N'COLUMN',@level2name=N'DTS'
GO
/****** Object:  Table [dbo].[DROUsages]    Script Date: 01/06/2012 15:02:53 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [DROUsages](
	[DROUsageID] [int] IDENTITY(1,1) NOT NULL,
	[DocID] [int] NOT NULL CONSTRAINT [DF_Table_1_ContentID]  DEFAULT ((0)),
	[ROID] [nvarchar](16) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
	[Config] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[DTS] [datetime] NOT NULL CONSTRAINT [DF_DROUsages_DTS]  DEFAULT (getdate()),
	[UserID] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_DROUsages_UserID]  DEFAULT (upper(suser_sname())),
	[LastChanged] [timestamp] NOT NULL,
	[RODbID] [int] NOT NULL,
 CONSTRAINT [PK_DROUsages] PRIMARY KEY CLUSTERED 
(
	[DROUsageID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'{datetime}' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'DROUsages', @level2type=N'COLUMN',@level2name=N'DTS'
GO
/****** Object:  Table [dbo].[ROImages]    Script Date: 01/06/2012 15:02:53 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [ROImages](
	[ImageID] [int] IDENTITY(1,1) NOT NULL,
	[RODbID] [int] NOT NULL,
	[FileName] [nvarchar](255) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
	[Content] [varbinary](max) NOT NULL,
	[Config] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[DTS] [datetime] NOT NULL CONSTRAINT [DF_ROImages_DTS]  DEFAULT (getdate()),
	[UserID] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_ROImages_UserID]  DEFAULT (upper(suser_sname())),
	[LastChanged] [timestamp] NOT NULL,
 CONSTRAINT [PK_ROImages] PRIMARY KEY CLUSTERED 
(
	[ImageID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
CREATE UNIQUE NONCLUSTERED INDEX [IX_ROImages_RODbID_FileName_DTS] ON [ROImages] 
(
	[RODbID] ASC,
	[FileName] ASC,
	[DTS] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'{datetime}' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'ROImages', @level2type=N'COLUMN',@level2name=N'DTS'
GO
/****** Object:  Table [dbo].[ROFsts]    Script Date: 01/06/2012 15:02:53 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [ROFsts](
	[ROFstID] [int] IDENTITY(1,1) NOT NULL,
	[RODbID] [int] NOT NULL,
	[ROLookup] [varbinary](max) NOT NULL,
	[Config] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[DTS] [datetime] NOT NULL CONSTRAINT [DF_Table_1_DTS1]  DEFAULT (getdate()),
	[UserID] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_ROFsts_UserID]  DEFAULT (upper(suser_sname())),
	[LastChanged] [timestamp] NOT NULL,
 CONSTRAINT [PK_ROFsts] PRIMARY KEY CLUSTERED 
(
	[ROFstID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
CREATE UNIQUE NONCLUSTERED INDEX [IX_ROFsts] ON [ROFsts] 
(
	[RODbID] ASC,
	[DTS] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'{datetime}' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'ROFsts', @level2type=N'COLUMN',@level2name=N'DTS'
GO
/****** Object:  Table [dbo].[RoUsages]    Script Date: 01/06/2012 15:02:53 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [RoUsages](
	[ROUsageID] [int] IDENTITY(1,1) NOT NULL,
	[ContentID] [int] NOT NULL CONSTRAINT [DF_RoUsages_StructureID]  DEFAULT ((0)),
	[ROID] [nvarchar](16) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
	[Config] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[DTS] [datetime] NOT NULL CONSTRAINT [DF_RoUsages_DTS]  DEFAULT (getdate()),
	[UserID] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_RoUsages_UserID]  DEFAULT (upper(suser_sname())),
	[LastChanged] [timestamp] NOT NULL,
	[RODbID] [int] NOT NULL,
 CONSTRAINT [PK_RoUsages] PRIMARY KEY CLUSTERED 
(
	[ROUsageID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_RoUsagesContentID] ON [RoUsages] 
(
	[ContentID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'{datetime}' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'RoUsages', @level2type=N'COLUMN',@level2name=N'DTS'
GO
/****** Object:  Table [dbo].[Figures]    Script Date: 01/06/2012 15:02:53 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [Figures](
	[FigureID] [int] IDENTITY(1,1) NOT NULL,
	[ROFstID] [int] NOT NULL,
	[ImageID] [int] NOT NULL,
	[Config] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[DTS] [datetime] NOT NULL CONSTRAINT [DF_Figures_DTS]  DEFAULT (getdate()),
	[UserID] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_Figures_UserID]  DEFAULT (upper(suser_sname())),
	[LastChanged] [timestamp] NOT NULL,
 CONSTRAINT [PK_Figures_1] PRIMARY KEY CLUSTERED 
(
	[FigureID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
CREATE UNIQUE NONCLUSTERED INDEX [IX_Figures_ROFstID_ImageID] ON [Figures] 
(
	[ROFstID] ASC,
	[ImageID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'{datetime}' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Figures', @level2type=N'COLUMN',@level2name=N'DTS'
GO
/****** Object:  Table [dbo].[Entries]    Script Date: 01/06/2012 15:02:53 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [Entries](
	[ContentID] [int] NOT NULL,
	[DocID] [int] NOT NULL,
	[DTS] [datetime] NOT NULL CONSTRAINT [DF_Entries_DTS]  DEFAULT (getdate()),
	[UserID] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_Entries_UserID]  DEFAULT (upper(suser_sname())),
	[LastChanged] [timestamp] NOT NULL,
 CONSTRAINT [PK_Entries] PRIMARY KEY CLUSTERED 
(
	[ContentID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_EntriesDocID] ON [Entries] 
(
	[DocID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'{datetime}' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Entries', @level2type=N'COLUMN',@level2name=N'DTS'
GO
/****** Object:  Table [dbo].[Pdfs]    Script Date: 01/06/2012 15:02:53 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [Pdfs](
	[DocID] [int] NOT NULL,
	[DebugStatus] [int] NOT NULL,
	[TopRow] [int] NOT NULL,
	[PageLength] [int] NOT NULL,
	[LeftMargin] [int] NOT NULL,
	[PageWidth] [int] NOT NULL,
	[PageCount] [float] NOT NULL,
	[DocPdf] [varbinary](max) NULL,
	[DTS] [datetime] NOT NULL CONSTRAINT [DF_Pdfs_DTS]  DEFAULT (getdate()),
	[UserID] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_Pdfs_UserID]  DEFAULT (upper(suser_sname())),
	[LastChanged] [timestamp] NOT NULL,
 CONSTRAINT [PK_Pdfs] PRIMARY KEY CLUSTERED 
(
	[DocID] ASC,
	[DebugStatus] ASC,
	[TopRow] ASC,
	[PageLength] ASC,
	[LeftMargin] ASC,
	[PageWidth] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'> 0 for Debug' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Pdfs', @level2type=N'COLUMN',@level2name=N'DebugStatus'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Count of whole and partial pages' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Pdfs', @level2type=N'COLUMN',@level2name=N'PageCount'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'{datetime}' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Pdfs', @level2type=N'COLUMN',@level2name=N'DTS'
GO
/****** Object:  Table [dbo].[Memberships]    Script Date: 01/06/2012 15:02:53 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [Memberships](
	[UGID] [int] IDENTITY(1,1) NOT NULL,
	[UID] [int] NOT NULL,
	[GID] [int] NOT NULL,
	[StartDate] [datetime] NOT NULL CONSTRAINT [DF_UserGroups_StartDate]  DEFAULT (getdate()),
	[EndDate] [datetime] NULL,
	[Config] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[DTS] [datetime] NOT NULL CONSTRAINT [DF_Memberships_DTS]  DEFAULT (getdate()),
	[UsrID] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_Memberships_UserID]  DEFAULT (upper(suser_sname())),
	[LastChanged] [timestamp] NOT NULL,
 CONSTRAINT [PK_UserGroups] PRIMARY KEY CLUSTERED 
(
	[UGID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_MembershipsGID] ON [Memberships] 
(
	[GID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_MembershipsUID] ON [Memberships] 
(
	[UID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'{datetime}' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Memberships', @level2type=N'COLUMN',@level2name=N'DTS'
GO
/****** Object:  Table [dbo].[Assignments]    Script Date: 01/06/2012 15:02:53 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [Assignments](
	[AID] [int] IDENTITY(1,1) NOT NULL,
	[GID] [int] NOT NULL,
	[RID] [int] NOT NULL,
	[FolderID] [int] NOT NULL,
	[StartDate] [datetime] NOT NULL CONSTRAINT [DF_Assignments_StartDate]  DEFAULT (getdate()),
	[EndDate] [datetime] NULL,
	[DTS] [datetime] NOT NULL CONSTRAINT [DF_Assignments_DTS]  DEFAULT (getdate()),
	[UsrID] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_Assignments_UsrID]  DEFAULT (upper(suser_sname())),
	[LastChanged] [timestamp] NOT NULL,
 CONSTRAINT [PK_Assignments] PRIMARY KEY CLUSTERED 
(
	[AID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_AssignmentsFolderID] ON [Assignments] 
(
	[FolderID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_AssignmentsGID] ON [Assignments] 
(
	[GID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_AssignmentsRID] ON [Assignments] 
(
	[RID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'{datetime}' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Assignments', @level2type=N'COLUMN',@level2name=N'DTS'
GO
/****** Object:  Table [dbo].[Parts]    Script Date: 01/06/2012 15:02:53 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [Parts](
	[ContentID] [int] NOT NULL,
	[FromType] [int] NOT NULL,
	[ItemID] [int] NOT NULL,
	[DTS] [datetime] NOT NULL CONSTRAINT [DF_Parts_DTS]  DEFAULT (getdate()),
	[UserID] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_Parts_UserID]  DEFAULT (upper(suser_sname())),
	[LastChanged] [timestamp] NOT NULL,
 CONSTRAINT [PK_Parts] PRIMARY KEY CLUSTERED 
(
	[ContentID] ASC,
	[FromType] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_PartsItemID] ON [Parts] 
(
	[ItemID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'{datetime}' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Parts', @level2type=N'COLUMN',@level2name=N'DTS'
GO
/****** Object:  Table [dbo].[DocVersions]    Script Date: 01/06/2012 15:02:53 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [DocVersions](
	[VersionID] [int] IDENTITY(1,1) NOT NULL,
	[FolderID] [int] NOT NULL,
	[VersionType] [int] NOT NULL CONSTRAINT [DF_Versions_VersionType]  DEFAULT ((0)),
	[Name] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
	[Title] [nvarchar](510) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[ItemID] [int] NULL,
	[FormatID] [int] NULL,
	[Config] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[DTS] [datetime] NOT NULL CONSTRAINT [DF_Versions_DTS]  DEFAULT (getdate()),
	[UserID] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_Versions_UserID]  DEFAULT (upper(suser_sname())),
	[LastChanged] [timestamp] NOT NULL,
 CONSTRAINT [PK_Versions] PRIMARY KEY CLUSTERED 
(
	[VersionID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_DocVersionsFolderID] ON [DocVersions] 
(
	[FolderID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_DocVersionsFormatID] ON [DocVersions] 
(
	[FormatID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_DocVersionsItemID] ON [DocVersions] 
(
	[ItemID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'0 Working Draft, 1 Temporary, 128 Revision, 129 Approved (Greater than 127  - non editable)' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'DocVersions', @level2type=N'COLUMN',@level2name=N'VersionType'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'{datetime}' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'DocVersions', @level2type=N'COLUMN',@level2name=N'DTS'
GO
/****** Object:  Table [dbo].[Transitions]    Script Date: 01/06/2012 15:02:53 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [Transitions](
	[TransitionID] [int] IDENTITY(1,1) NOT NULL,
	[FromID] [int] NOT NULL,
	[ToID] [int] NOT NULL,
	[RangeID] [int] NOT NULL,
	[IsRange] [int] NOT NULL CONSTRAINT [DF_Transitions_IsRange]  DEFAULT ((0)),
	[TranType] [int] NOT NULL CONSTRAINT [DF_Transitions_TranType]  DEFAULT ((0)),
	[Config] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[DTS] [datetime] NOT NULL CONSTRAINT [DF_Transitions_DTS]  DEFAULT (getdate()),
	[UserID] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_Transitions_UserID]  DEFAULT (upper(suser_sname())),
	[LastChanged] [timestamp] NOT NULL,
 CONSTRAINT [PK_TranUsages] PRIMARY KEY CLUSTERED 
(
	[TransitionID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_TransitionsFromID] ON [Transitions] 
(
	[FromID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_TransitionsRangeID] ON [Transitions] 
(
	[RangeID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_TransitionsToID] ON [Transitions] 
(
	[ToID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'StructureID' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Transitions', @level2type=N'COLUMN',@level2name=N'ToID'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'0 - Not a Range Transition, 1 - Range Transition, 2 - Range Transition - Extends to last Sibling' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Transitions', @level2type=N'COLUMN',@level2name=N'IsRange'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'{datetime}' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Transitions', @level2type=N'COLUMN',@level2name=N'DTS'
GO
/****** Object:  Table [dbo].[Annotations]    Script Date: 01/06/2012 15:02:53 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [Annotations](
	[AnnotationID] [int] IDENTITY(1,1) NOT NULL,
	[ItemID] [int] NOT NULL,
	[TypeID] [int] NOT NULL,
	[RtfText] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[SearchText] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Config] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[DTS] [datetime] NOT NULL CONSTRAINT [DF_Annotations_DTS]  DEFAULT (getdate()),
	[UserID] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_Annotations_UserID]  DEFAULT (upper(suser_sname())),
	[LastChanged] [timestamp] NOT NULL,
 CONSTRAINT [PK_Annotations] PRIMARY KEY CLUSTERED 
(
	[AnnotationID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_AnnotationsItemID] ON [Annotations] 
(
	[ItemID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_AnnotationsTypeID] ON [Annotations] 
(
	[TypeID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'{datetime}' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Annotations', @level2type=N'COLUMN',@level2name=N'DTS'
GO
/****** Object:  Table [dbo].[Contents]    Script Date: 01/06/2012 15:02:53 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [Contents](
	[ContentID] [int] IDENTITY(1,1) NOT NULL,
	[Number] [nvarchar](256) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Text] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Type] [int] NULL,
	[FormatID] [int] NULL,
	[Config] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[DTS] [datetime] NOT NULL CONSTRAINT [DF_Contents_DTS]  DEFAULT (getdate()),
	[UserID] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_Contents_UserID]  DEFAULT (upper(suser_sname())),
	[LastChanged] [timestamp] NOT NULL,
 CONSTRAINT [PK_Contents] PRIMARY KEY CLUSTERED 
(
	[ContentID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_ContentsFormatID] ON [Contents] 
(
	[FormatID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Increased from 30 to 256 to support RTF symbols' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Contents', @level2type=N'COLUMN',@level2name=N'Number'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'0 - Procedure, 10000 - Section, 20000 Step' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Contents', @level2type=N'COLUMN',@level2name=N'Type'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'{datetime}' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Contents', @level2type=N'COLUMN',@level2name=N'DTS'
GO
/****** Object:  Table [dbo].[Items]    Script Date: 01/06/2012 15:02:53 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [Items](
	[ItemID] [int] IDENTITY(1,1) NOT NULL,
	[PreviousID] [int] NULL,
	[ContentID] [int] NOT NULL,
	[DTS] [datetime] NOT NULL CONSTRAINT [DF_Items_DTS]  DEFAULT (getdate()),
	[UserID] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_Items_UsrID]  DEFAULT (upper(suser_sname())),
	[LastChanged] [timestamp] NOT NULL,
 CONSTRAINT [PK_Items] PRIMARY KEY CLUSTERED 
(
	[ItemID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_ItemsContentID] ON [Items] 
(
	[ContentID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_ItemsPreviousID] ON [Items] 
(
	[PreviousID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'{datetime}' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Items', @level2type=N'COLUMN',@level2name=N'DTS'
GO

/****** Object:  Table [dbo].[Scopes]    Script Date: 01/06/2012 15:02:52 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [Scopes](
	[ScopeID] [int] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](100) NOT NULL,
	[Title] [nvarchar](510) NULL,
	[DTS] [datetime] NOT NULL CONSTRAINT [DF_Scopes_DTS]  DEFAULT (getdate()),
	[UserID] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_Scopes_UserID]  DEFAULT (upper(suser_sname())),
	[LastChanged] [timestamp] NOT NULL,
 CONSTRAINT [PK_Scopes] PRIMARY KEY CLUSTERED 
(
	[ScopeID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'{datetime}' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Scopes', @level2type=N'COLUMN',@level2name=N'DTS'
GO

/****** Object:  Table [dbo].[Applicabilities]    Script Date: 01/06/2012 15:02:52 ******/
--SET ANSI_NULLS ON
--GO
--SET QUOTED_IDENTIFIER ON
--GO
--CREATE TABLE [Applicabilities](
--	[ItemID] [int] NOT NULL,
--	[ScopeID] [int] NOT NULL,
--	[DTS] [datetime] NOT NULL CONSTRAINT [DF_Applicabilities_DTS]  DEFAULT (getdate()),
--	[UserID] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_Applicabilities_UserID]  DEFAULT (upper(suser_sname())),
--	[LastChanged] [timestamp] NOT NULL,
-- CONSTRAINT [PK_Applicabilities] PRIMARY KEY CLUSTERED 
--(
--	[ItemID] ASC,
--	[ScopeID] ASC
--)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
--) ON [PRIMARY]
--GO
--EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'{datetime}' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Applicabilities', @level2type=N'COLUMN',@level2name=N'DTS'
--GO

/****** Object:  Table [dbo].[Details]    Script Date: 01/06/2012 15:02:53 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [Details](
	[DetailID] [int] IDENTITY(1,1) NOT NULL,
	[ContentID] [int] NOT NULL,
	[ItemType] [int] NOT NULL,
	[Text] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
	[Config] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[DTS] [datetime] NOT NULL CONSTRAINT [DF_StepTexts_DTS]  DEFAULT (getdate()),
	[UserID] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_StepTexts_UserID]  DEFAULT (upper(suser_sname())),
	[LastChanged] [timestamp] NOT NULL,
 CONSTRAINT [PK_StepTexts] PRIMARY KEY CLUSTERED 
(
	[DetailID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_DetailsContentID] ON [Details] 
(
	[ContentID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'{datetime}' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Details', @level2type=N'COLUMN',@level2name=N'DTS'
GO
/****** Object:  Table [dbo].[ZContents]    Script Date: 01/06/2012 15:02:53 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [ZContents](
	[ContentID] [int] NOT NULL,
	[OldStepSequence] [nvarchar](32) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
	[LastChanged] [timestamp] NOT NULL,
 CONSTRAINT [PK_ZContents] PRIMARY KEY CLUSTERED 
(
	[ContentID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[Grids]    Script Date: 01/06/2012 15:02:53 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [Grids](
	[ContentID] [int] NOT NULL,
	[Data] [xml] NOT NULL,
	[Config] [xml] NULL,
	[DTS] [datetime] NOT NULL CONSTRAINT [DF_Grids_DTS]  DEFAULT (getdate()),
	[UserID] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_Grids_UserID]  DEFAULT (upper(suser_sname())),
	[LastChanged] [timestamp] NOT NULL,
 CONSTRAINT [PK_Grids] PRIMARY KEY CLUSTERED 
(
	[ContentID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'{datetime}' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Grids', @level2type=N'COLUMN',@level2name=N'DTS'
GO
/****** Object:  Table [dbo].[Images]    Script Date: 01/06/2012 15:02:53 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [Images](
	[ContentID] [int] NOT NULL,
	[ImageType] [int] NOT NULL CONSTRAINT [DF_Images_ImageType]  DEFAULT ((1)),
	[FileName] [nvarchar](255) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
	[Data] [varbinary](max) NOT NULL,
	[Config] [xml] NULL,
	[DTS] [datetime] NOT NULL CONSTRAINT [DF_Images_DTS]  DEFAULT (getdate()),
	[UserID] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_Images_UserID]  DEFAULT (upper(suser_sname())),
	[LastChanged] [timestamp] NOT NULL,
 CONSTRAINT [PK_Images] PRIMARY KEY CLUSTERED 
(
	[ContentID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'1 - Figure, 2 - Video, 3 - Audio' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Images', @level2type=N'COLUMN',@level2name=N'ImageType'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'{datetime}' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Images', @level2type=N'COLUMN',@level2name=N'DTS'
GO
/****** Object:  Table [dbo].[ZTransitions]    Script Date: 01/06/2012 15:02:53 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [ZTransitions](
	[TransitionID] [int] NOT NULL,
	[oldto] [nvarchar](32) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
	[LastChanged] [timestamp] NOT NULL,
 CONSTRAINT [PK_ZTransitions] PRIMARY KEY CLUSTERED 
(
	[TransitionID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[Permissions]    Script Date: 01/06/2012 15:02:53 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [Permissions](
	[PID] [int] IDENTITY(1,1) NOT NULL,
	[RID] [int] NOT NULL,
	[PermLevel] [int] NOT NULL,
	[VersionType] [int] NOT NULL,
	[PermValue] [int] NOT NULL,
	[PermAD] [int] NOT NULL CONSTRAINT [DF_Permissions_PermAD]  DEFAULT ((0)),
	[StartDate] [datetime] NOT NULL CONSTRAINT [DF_Permissions_StartDate]  DEFAULT (getdate()),
	[EndDate] [datetime] NULL,
	[Config] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[DTS] [datetime] NOT NULL CONSTRAINT [DF_Permissions_DTS]  DEFAULT (getdate()),
	[UsrID] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_Permissions_UserID]  DEFAULT (upper(suser_sname())),
	[LastChanged] [timestamp] NOT NULL,
 CONSTRAINT [PK_Permissions] PRIMARY KEY CLUSTERED 
(
	[PID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_PermissionsRID] ON [Permissions] 
(
	[RID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'0 - None, 1 - Security, 2 - System, 3 - RO, 4 - Procdures, 5 - Sections, 6 - Steps, 7 - Comments' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Permissions', @level2type=N'COLUMN',@level2name=N'PermLevel'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'0 - None, 1 - Working Draft, 2 - Approved, (3 - All)' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Permissions', @level2type=N'COLUMN',@level2name=N'VersionType'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'1 - Read, 2 - Write, 4 - Create, 8 - Delete (15 - All)' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Permissions', @level2type=N'COLUMN',@level2name=N'PermValue'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'0 - Allow, 1 - Deny' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Permissions', @level2type=N'COLUMN',@level2name=N'PermAD'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'{datetime}' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Permissions', @level2type=N'COLUMN',@level2name=N'DTS'
GO
/****** Object:  ForeignKey [FK_Formats_ParentID]    Script Date: 01/06/2012 15:02:52 ******/
ALTER TABLE [Formats]  WITH CHECK ADD  CONSTRAINT [FK_Formats_ParentID] FOREIGN KEY([ParentID])
REFERENCES [Formats] ([FormatID])
GO
ALTER TABLE [Formats] CHECK CONSTRAINT [FK_Formats_ParentID]
GO
/****** Object:  ForeignKey [FK_Associations_DocVersions]    Script Date: 01/06/2012 15:02:52 ******/
ALTER TABLE [Associations]  WITH CHECK ADD  CONSTRAINT [FK_Associations_DocVersions] FOREIGN KEY([VersionID])
REFERENCES [DocVersions] ([VersionID])
GO
ALTER TABLE [Associations] CHECK CONSTRAINT [FK_Associations_DocVersions]
GO
/****** Object:  ForeignKey [FK_Associations_ROFsts]    Script Date: 01/06/2012 15:02:52 ******/
ALTER TABLE [Associations]  WITH CHECK ADD  CONSTRAINT [FK_Associations_ROFsts] FOREIGN KEY([ROFstID])
REFERENCES [ROFsts] ([ROFstID])
GO
ALTER TABLE [Associations] CHECK CONSTRAINT [FK_Associations_ROFsts]
GO
/****** Object:  ForeignKey [FK__Folders__ParentID]    Script Date: 01/06/2012 15:02:52 ******/
ALTER TABLE [Folders]  WITH CHECK ADD  CONSTRAINT [FK__Folders__ParentID] FOREIGN KEY([ParentID])
REFERENCES [Folders] ([FolderID])
GO
ALTER TABLE [Folders] CHECK CONSTRAINT [FK__Folders__ParentID]
GO
/****** Object:  ForeignKey [FK_Folders_Connections]    Script Date: 01/06/2012 15:02:52 ******/
ALTER TABLE [Folders]  WITH CHECK ADD  CONSTRAINT [FK_Folders_Connections] FOREIGN KEY([DBID])
REFERENCES [Connections] ([DBID])
GO
ALTER TABLE [Folders] CHECK CONSTRAINT [FK_Folders_Connections]
GO
/****** Object:  ForeignKey [FK_Folders_Formats]    Script Date: 01/06/2012 15:02:52 ******/
ALTER TABLE [Folders]  WITH CHECK ADD  CONSTRAINT [FK_Folders_Formats] FOREIGN KEY([FormatID])
REFERENCES [Formats] ([FormatID])
GO
ALTER TABLE [Folders] CHECK CONSTRAINT [FK_Folders_Formats]
GO
/****** Object:  ForeignKey [FK_DROUsages_Documents]    Script Date: 01/06/2012 15:02:53 ******/
ALTER TABLE [DROUsages]  WITH CHECK ADD  CONSTRAINT [FK_DROUsages_Documents] FOREIGN KEY([DocID])
REFERENCES [Documents] ([DocID])
GO
ALTER TABLE [DROUsages] CHECK CONSTRAINT [FK_DROUsages_Documents]
GO
/****** Object:  ForeignKey [FK_DROUsages_RODbs]    Script Date: 01/06/2012 15:02:53 ******/
ALTER TABLE [DROUsages]  WITH CHECK ADD  CONSTRAINT [FK_DROUsages_RODbs] FOREIGN KEY([RODbID])
REFERENCES [RODbs] ([RODbID])
GO
ALTER TABLE [DROUsages] CHECK CONSTRAINT [FK_DROUsages_RODbs]
GO
/****** Object:  ForeignKey [FK_Figures_RODbs]    Script Date: 01/06/2012 15:02:53 ******/
ALTER TABLE [ROImages]  WITH CHECK ADD  CONSTRAINT [FK_Figures_RODbs] FOREIGN KEY([RODbID])
REFERENCES [RODbs] ([RODbID])
GO
ALTER TABLE [ROImages] CHECK CONSTRAINT [FK_Figures_RODbs]
GO
/****** Object:  ForeignKey [FK_ROFsts_RODbs]    Script Date: 01/06/2012 15:02:53 ******/
ALTER TABLE [ROFsts]  WITH CHECK ADD  CONSTRAINT [FK_ROFsts_RODbs] FOREIGN KEY([RODbID])
REFERENCES [RODbs] ([RODbID])
GO
ALTER TABLE [ROFsts] CHECK CONSTRAINT [FK_ROFsts_RODbs]
GO
/****** Object:  ForeignKey [FK_RoUsages_Contents]    Script Date: 01/06/2012 15:02:53 ******/
ALTER TABLE [RoUsages]  WITH CHECK ADD  CONSTRAINT [FK_RoUsages_Contents] FOREIGN KEY([ContentID])
REFERENCES [Contents] ([ContentID])
GO
ALTER TABLE [RoUsages] CHECK CONSTRAINT [FK_RoUsages_Contents]
GO
/****** Object:  ForeignKey [FK_ROUsages_RODbs]    Script Date: 01/06/2012 15:02:53 ******/
ALTER TABLE [RoUsages]  WITH CHECK ADD  CONSTRAINT [FK_ROUsages_RODbs] FOREIGN KEY([RODbID])
REFERENCES [RODbs] ([RODbID])
GO
ALTER TABLE [RoUsages] CHECK CONSTRAINT [FK_ROUsages_RODbs]
GO
/****** Object:  ForeignKey [FK_Figures_ROFsts]    Script Date: 01/06/2012 15:02:53 ******/
ALTER TABLE [Figures]  WITH CHECK ADD  CONSTRAINT [FK_Figures_ROFsts] FOREIGN KEY([ROFstID])
REFERENCES [ROFsts] ([ROFstID])
GO
ALTER TABLE [Figures] CHECK CONSTRAINT [FK_Figures_ROFsts]
GO
/****** Object:  ForeignKey [FK_Figures_ROImages]    Script Date: 01/06/2012 15:02:53 ******/
ALTER TABLE [Figures]  WITH CHECK ADD  CONSTRAINT [FK_Figures_ROImages] FOREIGN KEY([ImageID])
REFERENCES [ROImages] ([ImageID])
GO
ALTER TABLE [Figures] CHECK CONSTRAINT [FK_Figures_ROImages]
GO
/****** Object:  ForeignKey [FK_Entries_Contents]    Script Date: 01/06/2012 15:02:53 ******/
ALTER TABLE [Entries]  WITH CHECK ADD  CONSTRAINT [FK_Entries_Contents] FOREIGN KEY([ContentID])
REFERENCES [Contents] ([ContentID])
GO
ALTER TABLE [Entries] CHECK CONSTRAINT [FK_Entries_Contents]
GO
/****** Object:  ForeignKey [FK_Entries_Documents]    Script Date: 01/06/2012 15:02:53 ******/
ALTER TABLE [Entries]  WITH CHECK ADD  CONSTRAINT [FK_Entries_Documents] FOREIGN KEY([DocID])
REFERENCES [Documents] ([DocID])
GO
ALTER TABLE [Entries] CHECK CONSTRAINT [FK_Entries_Documents]
GO
/****** Object:  ForeignKey [FK_Pdfs_Documents]    Script Date: 01/06/2012 15:02:53 ******/
ALTER TABLE [Pdfs]  WITH CHECK ADD  CONSTRAINT [FK_Pdfs_Documents] FOREIGN KEY([DocID])
REFERENCES [Documents] ([DocID])
GO
ALTER TABLE [Pdfs] CHECK CONSTRAINT [FK_Pdfs_Documents]
GO
/****** Object:  ForeignKey [FK_Memberships_Groups]    Script Date: 01/06/2012 15:02:53 ******/
ALTER TABLE [Memberships]  WITH CHECK ADD  CONSTRAINT [FK_Memberships_Groups] FOREIGN KEY([GID])
REFERENCES [Groups] ([GID])
GO
ALTER TABLE [Memberships] CHECK CONSTRAINT [FK_Memberships_Groups]
GO
/****** Object:  ForeignKey [FK_Memberships_Users]    Script Date: 01/06/2012 15:02:53 ******/
ALTER TABLE [Memberships]  WITH CHECK ADD  CONSTRAINT [FK_Memberships_Users] FOREIGN KEY([UID])
REFERENCES [Users] ([UID])
GO
ALTER TABLE [Memberships] CHECK CONSTRAINT [FK_Memberships_Users]
GO
/****** Object:  ForeignKey [FK_Assignments_Folders]    Script Date: 01/06/2012 15:02:53 ******/
ALTER TABLE [Assignments]  WITH CHECK ADD  CONSTRAINT [FK_Assignments_Folders] FOREIGN KEY([FolderID])
REFERENCES [Folders] ([FolderID])
GO
ALTER TABLE [Assignments] CHECK CONSTRAINT [FK_Assignments_Folders]
GO
/****** Object:  ForeignKey [FK_Assignments_Groups]    Script Date: 01/06/2012 15:02:53 ******/
ALTER TABLE [Assignments]  WITH CHECK ADD  CONSTRAINT [FK_Assignments_Groups] FOREIGN KEY([GID])
REFERENCES [Groups] ([GID])
GO
ALTER TABLE [Assignments] CHECK CONSTRAINT [FK_Assignments_Groups]
GO
/****** Object:  ForeignKey [FK_Assignments_Roles]    Script Date: 01/06/2012 15:02:53 ******/
ALTER TABLE [Assignments]  WITH CHECK ADD  CONSTRAINT [FK_Assignments_Roles] FOREIGN KEY([RID])
REFERENCES [Roles] ([RID])
GO
ALTER TABLE [Assignments] CHECK CONSTRAINT [FK_Assignments_Roles]
GO
/****** Object:  ForeignKey [FK_Parts_Contents]    Script Date: 01/06/2012 15:02:53 ******/
ALTER TABLE [Parts]  WITH CHECK ADD  CONSTRAINT [FK_Parts_Contents] FOREIGN KEY([ContentID])
REFERENCES [Contents] ([ContentID])
GO
ALTER TABLE [Parts] CHECK CONSTRAINT [FK_Parts_Contents]
GO
/****** Object:  ForeignKey [FK_Parts_Items]    Script Date: 01/06/2012 15:02:53 ******/
ALTER TABLE [Parts]  WITH CHECK ADD  CONSTRAINT [FK_Parts_Items] FOREIGN KEY([ItemID])
REFERENCES [Items] ([ItemID])
GO
ALTER TABLE [Parts] CHECK CONSTRAINT [FK_Parts_Items]
GO
/****** Object:  ForeignKey [FK_DocVersions_Formats]    Script Date: 01/06/2012 15:02:53 ******/
ALTER TABLE [DocVersions]  WITH CHECK ADD  CONSTRAINT [FK_DocVersions_Formats] FOREIGN KEY([FormatID])
REFERENCES [Formats] ([FormatID])
GO
ALTER TABLE [DocVersions] CHECK CONSTRAINT [FK_DocVersions_Formats]
GO
/****** Object:  ForeignKey [FK_DocVersions_Items]    Script Date: 01/06/2012 15:02:53 ******/
ALTER TABLE [DocVersions]  WITH CHECK ADD  CONSTRAINT [FK_DocVersions_Items] FOREIGN KEY([ItemID])
REFERENCES [Items] ([ItemID])
GO
ALTER TABLE [DocVersions] CHECK CONSTRAINT [FK_DocVersions_Items]
GO
/****** Object:  ForeignKey [FK_Versions_Folders]    Script Date: 01/06/2012 15:02:53 ******/
ALTER TABLE [DocVersions]  WITH CHECK ADD  CONSTRAINT [FK_Versions_Folders] FOREIGN KEY([FolderID])
REFERENCES [Folders] ([FolderID])
GO
ALTER TABLE [DocVersions] CHECK CONSTRAINT [FK_Versions_Folders]
GO
/****** Object:  ForeignKey [FK_TransitionsFromID_Contents]    Script Date: 01/06/2012 15:02:53 ******/
ALTER TABLE [Transitions]  WITH CHECK ADD  CONSTRAINT [FK_TransitionsFromID_Contents] FOREIGN KEY([FromID])
REFERENCES [Contents] ([ContentID])
GO
ALTER TABLE [Transitions] CHECK CONSTRAINT [FK_TransitionsFromID_Contents]
GO
/****** Object:  ForeignKey [FK_TransitionsRangeId_Items]    Script Date: 01/06/2012 15:02:53 ******/
ALTER TABLE [Transitions]  WITH CHECK ADD  CONSTRAINT [FK_TransitionsRangeId_Items] FOREIGN KEY([RangeID])
REFERENCES [Items] ([ItemID])
GO
ALTER TABLE [Transitions] CHECK CONSTRAINT [FK_TransitionsRangeId_Items]
GO
/****** Object:  ForeignKey [FK_TransitionsToId_Items]    Script Date: 01/06/2012 15:02:53 ******/
ALTER TABLE [Transitions]  WITH CHECK ADD  CONSTRAINT [FK_TransitionsToId_Items] FOREIGN KEY([ToID])
REFERENCES [Items] ([ItemID])
GO
ALTER TABLE [Transitions] CHECK CONSTRAINT [FK_TransitionsToId_Items]
GO
/****** Object:  ForeignKey [FK_Annotations_AnnotationTypes]    Script Date: 01/06/2012 15:02:53 ******/
ALTER TABLE [Annotations]  WITH CHECK ADD  CONSTRAINT [FK_Annotations_AnnotationTypes] FOREIGN KEY([TypeID])
REFERENCES [AnnotationTypes] ([TypeID])
GO
ALTER TABLE [Annotations] CHECK CONSTRAINT [FK_Annotations_AnnotationTypes]
GO
/****** Object:  ForeignKey [FK_Annotations_Items]    Script Date: 01/06/2012 15:02:53 ******/
ALTER TABLE [Annotations]  WITH CHECK ADD  CONSTRAINT [FK_Annotations_Items] FOREIGN KEY([ItemID])
REFERENCES [Items] ([ItemID])
GO
ALTER TABLE [Annotations] CHECK CONSTRAINT [FK_Annotations_Items]
GO
/****** Object:  ForeignKey [FK_Contents_Formats]    Script Date: 01/06/2012 15:02:53 ******/
ALTER TABLE [Contents]  WITH CHECK ADD  CONSTRAINT [FK_Contents_Formats] FOREIGN KEY([FormatID])
REFERENCES [Formats] ([FormatID])
GO
ALTER TABLE [Contents] CHECK CONSTRAINT [FK_Contents_Formats]
GO
/****** Object:  ForeignKey [FK_Items_Contents]    Script Date: 01/06/2012 15:02:53 ******/
ALTER TABLE [Items]  WITH CHECK ADD  CONSTRAINT [FK_Items_Contents] FOREIGN KEY([ContentID])
REFERENCES [Contents] ([ContentID])
GO
ALTER TABLE [Items] CHECK CONSTRAINT [FK_Items_Contents]
GO
/****** Object:  ForeignKey [FK_Items_Items]    Script Date: 01/06/2012 15:02:53 ******/
ALTER TABLE [Items]  WITH CHECK ADD  CONSTRAINT [FK_Items_Items] FOREIGN KEY([PreviousID])
REFERENCES [Items] ([ItemID])
GO
ALTER TABLE [Items] CHECK CONSTRAINT [FK_Items_Items]
GO
/****** Object:  ForeignKey [FK_Details_Contents]    Script Date: 01/06/2012 15:02:53 ******/
ALTER TABLE [Details]  WITH CHECK ADD  CONSTRAINT [FK_Details_Contents] FOREIGN KEY([ContentID])
REFERENCES [Contents] ([ContentID])
GO
ALTER TABLE [Details] CHECK CONSTRAINT [FK_Details_Contents]
GO
/****** Object:  ForeignKey [FK_ZContents_Contents]    Script Date: 01/06/2012 15:02:53 ******/
ALTER TABLE [ZContents]  WITH CHECK ADD  CONSTRAINT [FK_ZContents_Contents] FOREIGN KEY([ContentID])
REFERENCES [Contents] ([ContentID])
GO
ALTER TABLE [ZContents] CHECK CONSTRAINT [FK_ZContents_Contents]
GO
/****** Object:  ForeignKey [FK_Grids_Contents]    Script Date: 01/06/2012 15:02:53 ******/
ALTER TABLE [Grids]  WITH CHECK ADD  CONSTRAINT [FK_Grids_Contents] FOREIGN KEY([ContentID])
REFERENCES [Contents] ([ContentID])
GO
ALTER TABLE [Grids] CHECK CONSTRAINT [FK_Grids_Contents]
GO
/****** Object:  ForeignKey [FK_Images_Contents]    Script Date: 01/06/2012 15:02:53 ******/
ALTER TABLE [Images]  WITH CHECK ADD  CONSTRAINT [FK_Images_Contents] FOREIGN KEY([ContentID])
REFERENCES [Contents] ([ContentID])
GO
ALTER TABLE [Images] CHECK CONSTRAINT [FK_Images_Contents]
GO
/****** Object:  ForeignKey [FK_ZTransitions_Transitions]    Script Date: 01/06/2012 15:02:53 ******/
ALTER TABLE [ZTransitions]  WITH CHECK ADD  CONSTRAINT [FK_ZTransitions_Transitions] FOREIGN KEY([TransitionID])
REFERENCES [Transitions] ([TransitionID])
GO
ALTER TABLE [ZTransitions] CHECK CONSTRAINT [FK_ZTransitions_Transitions]
GO
/****** Object:  ForeignKey [FK_Permissions_Roles]    Script Date: 01/06/2012 15:02:53 ******/
ALTER TABLE [Permissions]  WITH CHECK ADD  CONSTRAINT [FK_Permissions_Roles] FOREIGN KEY([RID])
REFERENCES [Roles] ([RID])
GO
ALTER TABLE [Permissions] CHECK CONSTRAINT [FK_Permissions_Roles]
GO
--ALTER TABLE [dbo].[Applicabilities]  WITH CHECK ADD  CONSTRAINT [FK_Applicabilities_Items] FOREIGN KEY([ItemID])
--REFERENCES [dbo].[Items] ([ItemID])
--GO
--ALTER TABLE [dbo].[Applicabilities] CHECK CONSTRAINT [FK_Applicabilities_Items]
--GO
--ALTER TABLE [dbo].[Applicabilities]  WITH CHECK ADD  CONSTRAINT [FK_Applicabilities_Scopes] FOREIGN KEY([ScopeID])
--REFERENCES [dbo].[Scopes] ([ScopeID])
--GO
--ALTER TABLE [dbo].[Applicabilities] CHECK CONSTRAINT [FK_Applicabilities_Scopes]
--GO
/****** Object:  View [dbo].[vDuplicates1]    Script Date: 01/06/2012 15:02:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE view [vDuplicates1] as
SELECT Min(ContentID) MinID,Max(ContentID) MaxID,[Number],[Text],[Type],[FormatID],[Config],count(*) HowMany
  FROM [Contents]
where contentid not in (select contentid from parts)
group by [Number],[Text],[Type],[FormatID],[Config]
having count(*) > 1 and type >= 20000
GO
/****** Object:  View [dbo].[vDuplicates2]    Script Date: 01/06/2012 15:02:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create view [vDuplicates2] as
SELECT Min(ContentID) MinID,Max(ContentID) MaxID,[Number],[Text],[Type],[FormatID],[Config],count(*) HowMany
  FROM [Contents]
where contentid in (select contentid from parts)
group by [Number],[Text],[Type],[FormatID],[Config]
having count(*) > 1 and type >= 20000
GO
/****** Object:  Trigger [trigAddFolder]    Script Date: 01/06/2012 15:02:56 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE TRIGGER [trigAddFolder]
    ON [Folders]
    AFTER INSERT
AS
BEGIN

	SET NOCOUNT ON;
	--select max(fld.ManualOrder) from folders fld join inserted ins on fld.ParentID = Ins.ParentID
   --Select ROW_NUMBER() OVER(Partition by [ParentID] Order BY FolderID) + (select max(ManualOrder) from folders where ParentID = Inserted.ParentID) as RowNumber,* from Inserted
   Update Fld set Fld.ManualOrder = Ins.RowNumber
   From Folders Fld join
	(Select ROW_NUMBER() OVER(Partition by [ParentID] Order BY FolderID)  
+ (select isnull(max(ManualOrder),0) from folders where ParentID =
Inserted.ParentID) as RowNumber,* from Inserted)
	Ins on Ins.FolderID = Fld.FolderID
	Print 'Trigger Fired'
END
GO
INSERT INTO [Connections] ([Name]) VALUES ('Bozo')
INSERT INTO [Formats] ([Name],[Data]) VALUES ('Bozo',cast('<x/>' as xml))
INSERT INTO [Folders] ([Name],[ShortName],[ManualOrder]) VALUES ('Bozo','Bozo',1)
INSERT INTO [DocVersions] ([FolderID],[Name]) VALUES (1,'Bozo')
INSERT INTO [Contents]([Number]) VALUES('Bozo')
INSERT INTO [Items] ([ContentID]) VALUES (1)
INSERT INTO [RODbs] ([ROName],[FolderPath],[DBConnectionString]) VALUES ('Bozo','Bozo','Bozo')
INSERT INTO [ROFsts] ([RODbID],[ROLookup]) VALUES(1,Cast('Bozo' as varbinary))
Insert Into [Transitions] ([FromID],[ToID],[RangeID]) VALUES (1,1,1)
Insert Into [AnnotationTypes] ([Name]) VALUES ('Bozo')
Insert Into [Annotations] ([ItemID],[TypeID]) VALUES (1,1)
Insert Into [Groups] ([GroupName]) VALUES ('Bozo')
Insert Into [Details] ([ContentID],[ItemType],[Text]) VALUES (1,1,'Bozo')
Insert Into [Roles] ([Name],[Title]) VALUES ('Bozo','Bozo')
Insert Into [Permissions] ([RID],[PermLevel],[VersionType],[PermValue]) VALUES (1,1,1,1)
Insert Into [Scopes] ([Name]) VALUES ('Bozo')
--Insert Into [Applicabilities] ([ItemID],[ScopeID]) VALUES (1,1)
Insert Into [Associations] ([VersionID],[ROFstID]) VALUES (1,1)
INSERT INTO [Documents] ([LibTitle]) VALUES ('Bozo')
Insert Into [DROUsages] ([DocID],[ROID],[RODbID]) VALUES (1,'Bozo',1)
Insert Into [ROImages] ([RODbID],[FileName],[Content]) VALUES (1,'Bozo',cast ('Bozo' as varbinary))
Insert Into [RoUsages] ([ContentID],[ROID],[RODbID]) VALUES (1,1,1)
Insert Into [Figures] ([ROFstID],[ImageID]) VALUES (1,1)
INSERT INTO [Users] ([UserID]) VALUES ('Bozo')
Insert Into [Memberships] ([UID],[GID]) VALUES (1,1)
Insert Into [Assignments] ([GID],[RID],[FolderID]) VALUES (1,1,1)
GO
sp_changedbowner sa
GO
USE MASTER
GO
