/****** Object:  Table [dbo].[CalendarAvailabilities]    Script Date: 25.02.2015 03:38:03 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[CalendarAvailabilities]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[CalendarAvailabilities](
	[AvailabilityKey] [uniqueidentifier] NOT NULL,
	[CalendarKey] [uniqueidentifier] NOT NULL,
	[AvailabilityMode] [tinyint] NOT NULL,
	[StartDate] [datetime] NULL,
	[EndDate] [datetime] NULL,
	[Units] [float] NOT NULL,
	[LimitedHours] [float] NOT NULL,
	[ItemText] [nvarchar](255) NULL,
	[ImageIndex] [int] NOT NULL,
	[ModifiedDate] [datetime] NOT NULL,
	[ModifiedUser] [nvarchar](128) NULL,
 CONSTRAINT [PK_CalendarAvailabilities] PRIMARY KEY CLUSTERED 
(
	[AvailabilityKey] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[CalendarExceptions]    Script Date: 25.02.2015 03:38:03 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[CalendarExceptions]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[CalendarExceptions](
	[CalendarKey] [uniqueidentifier] NOT NULL,
	[ExceptionDate] [date] NOT NULL,
	[IsWorkingDay] [bit] NOT NULL CONSTRAINT [DF_CalendarExceptions_IsWorkingDay]  DEFAULT ((0))
) ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[Calendars]    Script Date: 25.02.2015 03:38:03 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Calendars]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Calendars](
	[ItemKey] [uniqueidentifier] NOT NULL,
	[ProjectKey] [uniqueidentifier] NULL,
	[ItemText] [nvarchar](255) NULL,
	[Description] [ntext] NULL,
	[InheritedCalendarKey] [uniqueidentifier] NULL,
	[IsResourceCalendar] [bit] NOT NULL CONSTRAINT [DF_Calendars_IsResourceCalendar]  DEFAULT ((0)),
	[IsTaskCalendar] [bit] NOT NULL CONSTRAINT [DF_Calendars_IsTaskCalendar]  DEFAULT ((0)),
	[HasWorkingHours] [bit] NOT NULL CONSTRAINT [DF_Calendars_InheritedWorkingDays]  DEFAULT ((0)),
	[WorkMonday] [bit] NOT NULL CONSTRAINT [DF_Calendars_WorkMonday]  DEFAULT ((0)),
	[WorkTuesday] [bit] NOT NULL CONSTRAINT [DF_Calendars_WorkTuesday]  DEFAULT ((0)),
	[WorkWednesday] [bit] NOT NULL CONSTRAINT [DF_Calendars_WorkWednesday]  DEFAULT ((0)),
	[WorkThursday] [bit] NOT NULL CONSTRAINT [DF_Calendars_WorkThursday]  DEFAULT ((0)),
	[WorkFriday] [bit] NOT NULL CONSTRAINT [DF_Calendars_WorkFriday]  DEFAULT ((0)),
	[WorkSaturday] [bit] NOT NULL CONSTRAINT [DF_Calendars_WorkSaturday]  DEFAULT ((0)),
	[WorkSunday] [bit] NOT NULL CONSTRAINT [DF_Calendars_WorkSunday]  DEFAULT ((0)),
	[ModifiedDate] [datetime] NOT NULL CONSTRAINT [DF_Calendars_ModifiedDate]  DEFAULT (getdate()),
	[ModifiedUser] [nvarchar](128) NULL CONSTRAINT [DF_Calendars_ModifiedUser]  DEFAULT (suser_sname()),
 CONSTRAINT [PK_Calendars] PRIMARY KEY CLUSTERED 
(
	[ItemKey] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[CalendarWorkingHours]    Script Date: 25.02.2015 03:38:03 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[CalendarWorkingHours]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[CalendarWorkingHours](
	[CalendarKey] [uniqueidentifier] NOT NULL,
	[DayOfWeek] [tinyint] NOT NULL,
	[StartHour] [real] NOT NULL,
	[EndHour] [real] NOT NULL,
	[ExceptionDate] [date] NULL
) ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[GlobalStringSettings]    Script Date: 25.02.2015 03:38:03 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GlobalStringSettings]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[GlobalStringSettings](
	[SettingsKey] [nvarchar](80) NOT NULL,
	[SettingsValue] [nvarchar](max) NULL,
	[UserId] [int] NULL,
 CONSTRAINT [PK_GlobalStringSettings] PRIMARY KEY CLUSTERED 
(
	[SettingsKey] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[GlobalXmlSettins]    Script Date: 25.02.2015 03:38:03 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GlobalXmlSettins]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[GlobalXmlSettins](
	[SettingsKey] [nvarchar](80) NOT NULL,
	[SettingsValue] [xml] NULL,
	[UserId] [int] NULL,
 CONSTRAINT [PK_GlobalXmlSettins] PRIMARY KEY CLUSTERED 
(
	[SettingsKey] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[Groups]    Script Date: 25.02.2015 03:38:03 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Groups]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Groups](
	[ItemKey] [uniqueidentifier] NOT NULL,
	[ProjectKey] [uniqueidentifier] NOT NULL,
	[WbsNumber] [varchar](255) NULL,
	[ItemText] [nvarchar](255) NULL,
	[Description] [ntext] NULL,
	[Properties] [xml] NULL,
	[FormatStyle] [xml] NULL,
	[FormatStyleTemplate] [xml] NULL,
	[ParentItemKey] [uniqueidentifier] NULL,
	[RowPosition] [int] NOT NULL,
	[ImageKey] [nvarchar](128) NULL,
	[ModifiedDate] [datetime] NOT NULL,
	[ModifiedUser] [nvarchar](128) NULL,
 CONSTRAINT [PK_Groups] PRIMARY KEY CLUSTERED 
(
	[ItemKey] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[ItemImages]    Script Date: 25.02.2015 03:38:03 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ItemImages]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[ItemImages](
	[ImageKey] [nvarchar](128) NOT NULL,
	[ImageData] [text] NOT NULL,
 CONSTRAINT [PK_ItemImages] PRIMARY KEY CLUSTERED 
(
	[ImageKey] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[ItemUserData]    Script Date: 25.02.2015 03:38:03 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ItemUserData]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[ItemUserData](
	[UserID] [int] NOT NULL,
	[TypeCode] [char](3) NOT NULL,
	[ItemKey] [uniqueidentifier] NOT NULL,
	[ProjectKey] [uniqueidentifier] NOT NULL,
	[UserData] [nvarchar](max) NULL,
 CONSTRAINT [PK_ItemUserData] PRIMARY KEY CLUSTERED 
(
	[UserID] ASC,
	[TypeCode] ASC,
	[ItemKey] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[ProjectBaselineData]    Script Date: 25.02.2015 03:38:03 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ProjectBaselineData]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[ProjectBaselineData](
	[BaselineKey] [uniqueidentifier] NOT NULL,
	[TaskKey] [uniqueidentifier] NOT NULL,
	[SplitRootItemKey] [uniqueidentifier] NULL,
	[StartDate] [datetime] NULL,
	[EndDate] [datetime] NULL,
	[PercentDone] [real] NULL,
	[TotalCost] [decimal](18, 0) NULL,
	[TotalWorkHours] [float] NULL,
	[DurationType] [tinyint] NOT NULL,
	[DurationDays] [float] NOT NULL,
	[TaskType] [tinyint] NOT NULL,
	[IsMilestone] [bit] NOT NULL,
	[Status] [tinyint] NOT NULL,
	[CalendarKey] [uniqueidentifier] NULL,
	[ProjectCalendarCombinationMode] [tinyint] NOT NULL,
	[Resources] [xml] NULL,
	[Predecessors] [xml] NULL,
	[Successors] [xml] NULL,
 CONSTRAINT [PK_ProjectBaselineItems] PRIMARY KEY CLUSTERED 
(
	[BaselineKey] ASC,
	[TaskKey] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[ProjectBaselines]    Script Date: 25.02.2015 03:38:03 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ProjectBaselines]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[ProjectBaselines](
	[ItemKey] [uniqueidentifier] NOT NULL,
	[ProjectKey] [uniqueidentifier] NOT NULL,
	[SnapshotDate] [datetime] NOT NULL,
	[BaselineType] [tinyint] NOT NULL,
	[ItemText] [nvarchar](255) NULL,
	[Description] [ntext] NULL,
	[Properties] [xml] NULL,
	[ModifiedDate] [datetime] NOT NULL,
	[ModifiedUser] [nvarchar](128) NULL,
 CONSTRAINT [PK_ProjectBaselines] PRIMARY KEY CLUSTERED 
(
	[ItemKey] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[Projects]    Script Date: 25.02.2015 03:38:03 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Projects]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Projects](
	[ItemKey] [uniqueidentifier] NOT NULL,
	[ProjectState] [tinyint] NOT NULL CONSTRAINT [DF_Projects_ProjectState]  DEFAULT ((0)),
	[ParentItemKey] [uniqueidentifier] NULL,
	[ItemText] [nvarchar](255) NULL,
	[Description] [ntext] NULL,
	[Properties] [xml] NULL,
	[Granularity] [smallint] NOT NULL CONSTRAINT [DF_Projects_Granularity]  DEFAULT ((2)),
	[StartDate] [datetime] NULL,
	[EndDate] [datetime] NULL,
	[DefaultTaskType] [tinyint] NOT NULL CONSTRAINT [DF_Projects_DefaultTaskType]  DEFAULT ((1)),
	[DefaultDurationType] [tinyint] NOT NULL CONSTRAINT [DF_Projects_DefaultDurationType]  DEFAULT ((0)),
	[NewTaskCount] [int] NOT NULL CONSTRAINT [DF_Projects_NewTaskCount]  DEFAULT ((0)),
	[RandomBarColors] [bit] NOT NULL CONSTRAINT [DF_Projects_RandomBarColors]  DEFAULT ((1)),
	[ColorCyclerCurrentIndex] [int] NOT NULL CONSTRAINT [DF_Projects_ColorCyclerCurrentIndex]  DEFAULT ((0)),
	[ResourceBarColorTolerance] [float] NOT NULL CONSTRAINT [DF_Projects_ResourceBarColorTolerance]  DEFAULT ((0.1)),
	[ShowHappinessIcon] [bit] NOT NULL CONSTRAINT [DF_Projects_ShowHappinessIcon]  DEFAULT ((0)),
	[DataColumnsGantt] [xml] NULL,
	[DataColumnsResources] [xml] NULL,
	[DataColumnsResourcePlan] [xml] NULL,
	[FormatStyleTemplates] [xml] NULL,
	[Manager] [nvarchar](255) NULL,
	[ColorPalette] [nvarchar](50) NULL,
	[WbsNumberingMode] [tinyint] NOT NULL CONSTRAINT [DF_Projects_WbsNumberingMode]  DEFAULT ((0)),
	[ModifiedDate] [datetime] NOT NULL CONSTRAINT [DF_Projects_ModifiedDate]  DEFAULT (getdate()),
	[ModifiedUser] [nvarchar](128) NULL CONSTRAINT [DF_Projects_ModifiedUser]  DEFAULT (suser_sname()),
 CONSTRAINT [PK_Projects] PRIMARY KEY CLUSTERED 
(
	[ItemKey] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[ResourceAllocations]    Script Date: 25.02.2015 03:38:03 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ResourceAllocations]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[ResourceAllocations](
	[ResourceKey] [uniqueidentifier] NOT NULL,
	[TaskKey] [uniqueidentifier] NOT NULL,
	[SplitRootItemKey] [uniqueidentifier] NULL,
	[TaskCalendarKey] [uniqueidentifier] NULL,
	[TaskCalendarCombinationMode] [tinyint] NOT NULL CONSTRAINT [DF_ResourceAllocations_TaskCalendarCombinationMode]  DEFAULT ((0)),
	[ProjectKey] [uniqueidentifier] NOT NULL,
	[StartDate] [datetime] NOT NULL,
	[EndDate] [datetime] NOT NULL,
	[Unit] [real] NOT NULL CONSTRAINT [DF_ResourceAllocations_Unit]  DEFAULT ((1)),
	[TaskText] [nvarchar](255) NULL,
	[ProjectText] [nvarchar](255) NULL,
	[TaskStatus] [tinyint] NOT NULL CONSTRAINT [DF_ResourceAllocations_TaskStatus]  DEFAULT ((0)),
	[PercentDone] [real] NOT NULL CONSTRAINT [DF_ResourceAllocations_PercentDone]  DEFAULT ((0)),
	[Priority] [tinyint] NOT NULL CONSTRAINT [DF_ResourceAllocations_Priority]  DEFAULT ((2)),
 CONSTRAINT [PK_ResourceAllocations] PRIMARY KEY CLUSTERED 
(
	[ResourceKey] ASC,
	[TaskKey] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[ResourceRelations]    Script Date: 25.02.2015 03:38:03 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ResourceRelations]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[ResourceRelations](
	[TaskKey] [uniqueidentifier] NOT NULL,
	[ResourceKey] [uniqueidentifier] NOT NULL,
	[ProjectKey] [uniqueidentifier] NOT NULL,
	[Unit] [real] NOT NULL CONSTRAINT [DF_ResourceRelations_Unit]  DEFAULT ((1.0)),
	[ProposedUnit] [real] NOT NULL CONSTRAINT [DF_ResourceRelations_ProposedUnit]  DEFAULT ((-1.0)),
	[Responsible] [bit] NOT NULL CONSTRAINT [DF_Task2Resource_Responsible]  DEFAULT ((0)),
 CONSTRAINT [PK_Task2Resource] PRIMARY KEY CLUSTERED 
(
	[TaskKey] ASC,
	[ResourceKey] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[Resources]    Script Date: 25.02.2015 03:38:03 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Resources]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Resources](
	[ItemKey] [uniqueidentifier] NOT NULL,
	[ProjectKey] [uniqueidentifier] NULL,
	[ItemText] [nvarchar](255) NULL,
	[Description] [ntext] NULL,
	[Properties] [xml] NULL,
	[ResourceType] [tinyint] NOT NULL CONSTRAINT [DF_Resources_ResourceType]  DEFAULT ((0)),
	[Role] [nvarchar](255) NULL,
	[CostPerHour] [money] NULL,
	[CostPerCalendarDay] [money] NULL,
	[FixedCost] [money] NULL,
	[TotalCost] [money] NULL,
	[CalendarKey] [uniqueidentifier] NULL,
	[ProjectCalendarCombinationMode] [tinyint] NOT NULL CONSTRAINT [DF_Resources_ProjectCalendarCombinationMode]  DEFAULT ((0)),
	[TaskCalendarCombinationMode] [tinyint] NOT NULL CONSTRAINT [DF_Resources_TaskCalendarCombinationMode]  DEFAULT ((0)),
	[ParentItemKey] [uniqueidentifier] NULL,
	[RowPosition] [int] NOT NULL CONSTRAINT [DF_Resources_RowPosition_1]  DEFAULT ((0)),
	[ImageKey] [nvarchar](128) NULL,
	[ModifiedDate] [datetime] NOT NULL CONSTRAINT [DF_Resources_ModifiedDate]  DEFAULT (getdate()),
	[ModifiedUser] [nvarchar](128) NULL CONSTRAINT [DF_Resources_ModifiedUser]  DEFAULT (suser_sname()),
 CONSTRAINT [PK_Resources] PRIMARY KEY CLUSTERED 
(
	[ItemKey] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[ResourceSkills]    Script Date: 25.02.2015 03:38:03 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ResourceSkills]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[ResourceSkills](
	[ResourceKey] [uniqueidentifier] NOT NULL,
	[SkillKey] [uniqueidentifier] NOT NULL,
	[Productivity] [float] NOT NULL,
 CONSTRAINT [PK_ResourceSkills] PRIMARY KEY CLUSTERED 
(
	[ResourceKey] ASC,
	[SkillKey] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[Skills]    Script Date: 25.02.2015 03:38:03 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Skills]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Skills](
	[ItemKey] [uniqueidentifier] NOT NULL,
	[ProjectKey] [uniqueidentifier] NULL,
	[ItemText] [nvarchar](255) NULL,
	[Description] [ntext] NULL,
	[ModifiedDate] [datetime] NOT NULL,
	[ModifiedUser] [nvarchar](128) NULL,
 CONSTRAINT [PK_Skills] PRIMARY KEY CLUSTERED 
(
	[ItemKey] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[TaskRelations]    Script Date: 25.02.2015 03:38:03 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TaskRelations]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TaskRelations](
	[TaskKey] [uniqueidentifier] NOT NULL,
	[DependingTaskKey] [uniqueidentifier] NOT NULL,
	[ProjectKey] [uniqueidentifier] NOT NULL,
	[DelayDays] [float] NOT NULL,
	[DelayDurationType] [tinyint] NOT NULL,
	[TaskRelationMode] [tinyint] NOT NULL,
	[TaskRelationType] [tinyint] NOT NULL,
 CONSTRAINT [PK_Task2Task] PRIMARY KEY CLUSTERED 
(
	[TaskKey] ASC,
	[DependingTaskKey] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[Tasks]    Script Date: 25.02.2015 03:38:03 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Tasks]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Tasks](
	[ItemKey] [uniqueidentifier] NOT NULL,
	[ProjectKey] [uniqueidentifier] NOT NULL,
	[WbsNumber] [varchar](255) NULL,
	[ItemText] [nvarchar](255) NULL,
	[Description] [ntext] NULL,
	[StartDate] [datetime] NOT NULL,
	[EndDate] [datetime] NOT NULL,
	[Properties] [xml] NULL,
	[FormatStyle] [xml] NULL,
	[FormatStyleTemplate] [xml] NULL,
	[ParentItemKey] [uniqueidentifier] NULL,
	[SplitRootItemKey] [uniqueidentifier] NULL,
	[PercentDone] [real] NULL,
	[EarliestStartDate] [datetime] NULL,
	[LatestStartDate] [datetime] NULL,
	[EarliestEndDate] [datetime] NULL,
	[LatestEndDate] [datetime] NULL,
	[StartDateRule] [tinyint] NOT NULL CONSTRAINT [DF_Tasks_StartDateRule]  DEFAULT ((0)),
	[EndDateRule] [tinyint] NOT NULL CONSTRAINT [DF_Tasks_EndDateRule]  DEFAULT ((0)),
	[IsMilestone] [bit] NOT NULL CONSTRAINT [DF_Tasks_IsMilestone]  DEFAULT ((0)),
	[Priority] [tinyint] NOT NULL CONSTRAINT [DF_Tasks_Priority]  DEFAULT ((2)),
	[Status] [tinyint] NOT NULL CONSTRAINT [DF_Tasks_Status]  DEFAULT ((0)),
	[TaskType] [tinyint] NOT NULL CONSTRAINT [DF_Tasks_TaskType]  DEFAULT ((1)),
	[Estimated] [bit] NOT NULL CONSTRAINT [DF_Tasks_Estimated]  DEFAULT ((0)),
	[DurationType] [tinyint] NOT NULL CONSTRAINT [DF_Tasks_DurationType]  DEFAULT ((0)),
	[DurationDays] [float] NOT NULL CONSTRAINT [DF_Tasks_DurationDays]  DEFAULT ((0)),
	[CalendarKey] [uniqueidentifier] NULL,
	[ProjectCalendarCombinationMode] [tinyint] NOT NULL CONSTRAINT [DF_Tasks_ProjectCalendarCombinationMode]  DEFAULT ((0)),
	[ASAP] [bit] NOT NULL CONSTRAINT [DF_Tasks_ASAP]  DEFAULT ((0)),
	[CostPerHour] [money] NULL,
	[CostPerCalendarDay] [money] NULL,
	[FixedCost] [money] NULL,
	[TotalCost] [money] NULL,
	[RowPosition] [int] NOT NULL CONSTRAINT [DF_Tasks_RowPosition]  DEFAULT ((0)),
	[ImageKey] [nvarchar](128) NULL,
	[PausedDate] [datetime] NULL,
	[ModifiedDate] [datetime] NOT NULL CONSTRAINT [DF_Tasks_ModifiedDate]  DEFAULT (getdate()),
	[ModifiedUser] [nvarchar](128) NULL CONSTRAINT [DF_Tasks_ModifiedUser]  DEFAULT (suser_sname()),
 CONSTRAINT [PK_Tasks] PRIMARY KEY CLUSTERED 
(
	[ItemKey] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[WorkPreferredResources]    Script Date: 25.02.2015 03:38:03 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[WorkPreferredResources]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[WorkPreferredResources](
	[WorkKey] [uniqueidentifier] NOT NULL,
	[ResourceKey] [uniqueidentifier] NOT NULL,
 CONSTRAINT [PK_WorkPreferredResources] PRIMARY KEY CLUSTERED 
(
	[WorkKey] ASC,
	[ResourceKey] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[Works]    Script Date: 25.02.2015 03:38:03 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Works]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Works](
	[ItemKey] [uniqueidentifier] NOT NULL,
	[TaskKey] [uniqueidentifier] NOT NULL,
	[ProjectKey] [uniqueidentifier] NOT NULL,
	[ItemText] [nvarchar](255) NULL,
	[Description] [ntext] NULL,
	[WorkHours] [float] NOT NULL CONSTRAINT [DF_Works_WorkHours]  DEFAULT ((0)),
	[ProposedWorkHours] [float] NOT NULL CONSTRAINT [DF_Works_ProposedWorkHours]  DEFAULT ((-1.0)),
	[SkillKey] [uniqueidentifier] NULL,
	[MaxEntities] [int] NOT NULL CONSTRAINT [DF_Works_MaxEntities]  DEFAULT ((0)),
 CONSTRAINT [PK_Works] PRIMARY KEY CLUSTERED 
(
	[ItemKey] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
GO
/****** Object:  Index [IX_CalendarAvailabilitiesCalendarKey]    Script Date: 25.02.2015 03:38:03 ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[CalendarAvailabilities]') AND name = N'IX_CalendarAvailabilitiesCalendarKey')
CREATE NONCLUSTERED INDEX [IX_CalendarAvailabilitiesCalendarKey] ON [dbo].[CalendarAvailabilities]
(
	[CalendarKey] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [IX_CalendarExceptions]    Script Date: 25.02.2015 03:38:03 ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[CalendarExceptions]') AND name = N'IX_CalendarExceptions')
CREATE NONCLUSTERED INDEX [IX_CalendarExceptions] ON [dbo].[CalendarExceptions]
(
	[CalendarKey] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [IX_Calendars]    Script Date: 25.02.2015 03:38:03 ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Calendars]') AND name = N'IX_Calendars')
CREATE NONCLUSTERED INDEX [IX_Calendars] ON [dbo].[Calendars]
(
	[ProjectKey] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [IX_CalendarWorkingHours]    Script Date: 25.02.2015 03:38:03 ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[CalendarWorkingHours]') AND name = N'IX_CalendarWorkingHours')
CREATE NONCLUSTERED INDEX [IX_CalendarWorkingHours] ON [dbo].[CalendarWorkingHours]
(
	[CalendarKey] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [IX_Groups]    Script Date: 25.02.2015 03:38:03 ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Groups]') AND name = N'IX_Groups')
CREATE NONCLUSTERED INDEX [IX_Groups] ON [dbo].[Groups]
(
	[ProjectKey] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [IX_ItemUserDataItemKey]    Script Date: 25.02.2015 03:38:03 ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[ItemUserData]') AND name = N'IX_ItemUserDataItemKey')
CREATE NONCLUSTERED INDEX [IX_ItemUserDataItemKey] ON [dbo].[ItemUserData]
(
	[ItemKey] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [IX_ItemUserDataProjectKey]    Script Date: 25.02.2015 03:38:03 ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[ItemUserData]') AND name = N'IX_ItemUserDataProjectKey')
CREATE NONCLUSTERED INDEX [IX_ItemUserDataProjectKey] ON [dbo].[ItemUserData]
(
	[ProjectKey] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [IX_ProjectBaselinesProjectKey]    Script Date: 25.02.2015 03:38:03 ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[ProjectBaselines]') AND name = N'IX_ProjectBaselinesProjectKey')
CREATE NONCLUSTERED INDEX [IX_ProjectBaselinesProjectKey] ON [dbo].[ProjectBaselines]
(
	[ProjectKey] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [IX_ResourceAllocations]    Script Date: 25.02.2015 03:38:03 ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[ResourceAllocations]') AND name = N'IX_ResourceAllocations')
CREATE NONCLUSTERED INDEX [IX_ResourceAllocations] ON [dbo].[ResourceAllocations]
(
	[StartDate] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [IX_ResourceAllocations_1]    Script Date: 25.02.2015 03:38:03 ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[ResourceAllocations]') AND name = N'IX_ResourceAllocations_1')
CREATE NONCLUSTERED INDEX [IX_ResourceAllocations_1] ON [dbo].[ResourceAllocations]
(
	[ProjectKey] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [IX_ResourceAllocations_2]    Script Date: 25.02.2015 03:38:03 ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[ResourceAllocations]') AND name = N'IX_ResourceAllocations_2')
CREATE NONCLUSTERED INDEX [IX_ResourceAllocations_2] ON [dbo].[ResourceAllocations]
(
	[TaskKey] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [IX_Task2Resource]    Script Date: 25.02.2015 03:38:03 ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[ResourceRelations]') AND name = N'IX_Task2Resource')
CREATE NONCLUSTERED INDEX [IX_Task2Resource] ON [dbo].[ResourceRelations]
(
	[ResourceKey] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [IX_Task2Resource_1]    Script Date: 25.02.2015 03:38:03 ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[ResourceRelations]') AND name = N'IX_Task2Resource_1')
CREATE NONCLUSTERED INDEX [IX_Task2Resource_1] ON [dbo].[ResourceRelations]
(
	[ProjectKey] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [IX_Resources]    Script Date: 25.02.2015 03:38:03 ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Resources]') AND name = N'IX_Resources')
CREATE NONCLUSTERED INDEX [IX_Resources] ON [dbo].[Resources]
(
	[ProjectKey] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [IX_Skills]    Script Date: 25.02.2015 03:38:03 ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Skills]') AND name = N'IX_Skills')
CREATE NONCLUSTERED INDEX [IX_Skills] ON [dbo].[Skills]
(
	[ProjectKey] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [IX_Task2Task]    Script Date: 25.02.2015 03:38:03 ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[TaskRelations]') AND name = N'IX_Task2Task')
CREATE NONCLUSTERED INDEX [IX_Task2Task] ON [dbo].[TaskRelations]
(
	[ProjectKey] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [IX_Tasks_ProjectKey]    Script Date: 25.02.2015 03:38:03 ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Tasks]') AND name = N'IX_Tasks_ProjectKey')
CREATE NONCLUSTERED INDEX [IX_Tasks_ProjectKey] ON [dbo].[Tasks]
(
	[ProjectKey] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [IX_Tasks_SplitParentItemKey]    Script Date: 25.02.2015 03:38:03 ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Tasks]') AND name = N'IX_Tasks_SplitParentItemKey')
CREATE NONCLUSTERED INDEX [IX_Tasks_SplitParentItemKey] ON [dbo].[Tasks]
(
	[SplitRootItemKey] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [IX_WorkPreferredResources]    Script Date: 25.02.2015 03:38:03 ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[WorkPreferredResources]') AND name = N'IX_WorkPreferredResources')
CREATE NONCLUSTERED INDEX [IX_WorkPreferredResources] ON [dbo].[WorkPreferredResources]
(
	[ResourceKey] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [IX_Works]    Script Date: 25.02.2015 03:38:03 ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Works]') AND name = N'IX_Works')
CREATE NONCLUSTERED INDEX [IX_Works] ON [dbo].[Works]
(
	[TaskKey] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [IX_Works_1]    Script Date: 25.02.2015 03:38:03 ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Works]') AND name = N'IX_Works_1')
CREATE NONCLUSTERED INDEX [IX_Works_1] ON [dbo].[Works]
(
	[ProjectKey] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[DF_CalendarAvailabilities_AvailabilityMode]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[CalendarAvailabilities] ADD  CONSTRAINT [DF_CalendarAvailabilities_AvailabilityMode]  DEFAULT ((1)) FOR [AvailabilityMode]
END

GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[DF_CalendarAvailabilities_Units]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[CalendarAvailabilities] ADD  CONSTRAINT [DF_CalendarAvailabilities_Units]  DEFAULT ((1.0)) FOR [Units]
END

GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[DF_CalendarAvailabilities_LimitedHours]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[CalendarAvailabilities] ADD  CONSTRAINT [DF_CalendarAvailabilities_LimitedHours]  DEFAULT ((0)) FOR [LimitedHours]
END

GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[DF_CalendarAvailabilities_ImageIndex]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[CalendarAvailabilities] ADD  CONSTRAINT [DF_CalendarAvailabilities_ImageIndex]  DEFAULT ((-1)) FOR [ImageIndex]
END

GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[DF_CalendarAvailabilities_ModifiedDate]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[CalendarAvailabilities] ADD  CONSTRAINT [DF_CalendarAvailabilities_ModifiedDate]  DEFAULT (getdate()) FOR [ModifiedDate]
END

GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[DF_CalendarAvailabilities_ModifiedUser]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[CalendarAvailabilities] ADD  CONSTRAINT [DF_CalendarAvailabilities_ModifiedUser]  DEFAULT (suser_sname()) FOR [ModifiedUser]
END

GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[DF_Groups_RowPosition]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[Groups] ADD  CONSTRAINT [DF_Groups_RowPosition]  DEFAULT ((0)) FOR [RowPosition]
END

GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[DF_Groups_ModifiedDate]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[Groups] ADD  CONSTRAINT [DF_Groups_ModifiedDate]  DEFAULT (getdate()) FOR [ModifiedDate]
END

GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[DF_Groups_ModifiedUser]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[Groups] ADD  CONSTRAINT [DF_Groups_ModifiedUser]  DEFAULT (suser_sname()) FOR [ModifiedUser]
END

GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[DF_ItemUserData_ModifiedUser]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[ItemUserData] ADD  CONSTRAINT [DF_ItemUserData_ModifiedUser]  DEFAULT (database_principal_id()) FOR [UserID]
END

GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[DF_ProjectBaselineItems_DurationType]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[ProjectBaselineData] ADD  CONSTRAINT [DF_ProjectBaselineItems_DurationType]  DEFAULT ((0)) FOR [DurationType]
END

GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[DF_ProjectBaselineItems_DurationDays]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[ProjectBaselineData] ADD  CONSTRAINT [DF_ProjectBaselineItems_DurationDays]  DEFAULT ((0)) FOR [DurationDays]
END

GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[DF_ProjectBaselineItems_IsMilestone]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[ProjectBaselineData] ADD  CONSTRAINT [DF_ProjectBaselineItems_IsMilestone]  DEFAULT ((0)) FOR [IsMilestone]
END

GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[DF_ProjectBaselineItems_ProjectCalendarCombinationMode]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[ProjectBaselineData] ADD  CONSTRAINT [DF_ProjectBaselineItems_ProjectCalendarCombinationMode]  DEFAULT ((0)) FOR [ProjectCalendarCombinationMode]
END

GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[DF_ProjectBaselines_SnapshotDate]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[ProjectBaselines] ADD  CONSTRAINT [DF_ProjectBaselines_SnapshotDate]  DEFAULT (getdate()) FOR [SnapshotDate]
END

GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[DF_ProjectBaselines_BaselineType]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[ProjectBaselines] ADD  CONSTRAINT [DF_ProjectBaselines_BaselineType]  DEFAULT ((0)) FOR [BaselineType]
END

GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[DF_ProjectBaselines_ModifiedDate]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[ProjectBaselines] ADD  CONSTRAINT [DF_ProjectBaselines_ModifiedDate]  DEFAULT (getdate()) FOR [ModifiedDate]
END

GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[DF_ProjectBaselines_ModifiedUser]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[ProjectBaselines] ADD  CONSTRAINT [DF_ProjectBaselines_ModifiedUser]  DEFAULT (suser_sname()) FOR [ModifiedUser]
END

GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[DF_ResourceSkills_Productivity]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[ResourceSkills] ADD  CONSTRAINT [DF_ResourceSkills_Productivity]  DEFAULT ((1.0)) FOR [Productivity]
END

GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[DF_Skills_ModifiedDate]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[Skills] ADD  CONSTRAINT [DF_Skills_ModifiedDate]  DEFAULT (getdate()) FOR [ModifiedDate]
END

GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[DF_Skills_ModifiedUser]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[Skills] ADD  CONSTRAINT [DF_Skills_ModifiedUser]  DEFAULT (suser_sname()) FOR [ModifiedUser]
END

GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[DF_TaskRelations_DelayDays]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[TaskRelations] ADD  CONSTRAINT [DF_TaskRelations_DelayDays]  DEFAULT ((0)) FOR [DelayDays]
END

GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[DF_TaskRelations_DelayDurationType]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[TaskRelations] ADD  CONSTRAINT [DF_TaskRelations_DelayDurationType]  DEFAULT ((0)) FOR [DelayDurationType]
END

GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[DF_TaskRelations_TaskRelationMode]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[TaskRelations] ADD  CONSTRAINT [DF_TaskRelations_TaskRelationMode]  DEFAULT ((1)) FOR [TaskRelationMode]
END

GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[DF_TaskRelations_TaskRelationType]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[TaskRelations] ADD  CONSTRAINT [DF_TaskRelations_TaskRelationType]  DEFAULT ((0)) FOR [TaskRelationType]
END

GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_CalendarAvailabilities_Calendars]') AND parent_object_id = OBJECT_ID(N'[dbo].[CalendarAvailabilities]'))
ALTER TABLE [dbo].[CalendarAvailabilities]  WITH CHECK ADD  CONSTRAINT [FK_CalendarAvailabilities_Calendars] FOREIGN KEY([CalendarKey])
REFERENCES [dbo].[Calendars] ([ItemKey])
ON UPDATE CASCADE
ON DELETE CASCADE
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_CalendarAvailabilities_Calendars]') AND parent_object_id = OBJECT_ID(N'[dbo].[CalendarAvailabilities]'))
ALTER TABLE [dbo].[CalendarAvailabilities] CHECK CONSTRAINT [FK_CalendarAvailabilities_Calendars]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_CalendarExceptions_Calendars1]') AND parent_object_id = OBJECT_ID(N'[dbo].[CalendarExceptions]'))
ALTER TABLE [dbo].[CalendarExceptions]  WITH NOCHECK ADD  CONSTRAINT [FK_CalendarExceptions_Calendars1] FOREIGN KEY([CalendarKey])
REFERENCES [dbo].[Calendars] ([ItemKey])
ON UPDATE CASCADE
ON DELETE CASCADE
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_CalendarExceptions_Calendars1]') AND parent_object_id = OBJECT_ID(N'[dbo].[CalendarExceptions]'))
ALTER TABLE [dbo].[CalendarExceptions] CHECK CONSTRAINT [FK_CalendarExceptions_Calendars1]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Calendars_Projects]') AND parent_object_id = OBJECT_ID(N'[dbo].[Calendars]'))
ALTER TABLE [dbo].[Calendars]  WITH NOCHECK ADD  CONSTRAINT [FK_Calendars_Projects] FOREIGN KEY([ProjectKey])
REFERENCES [dbo].[Projects] ([ItemKey])
ON UPDATE CASCADE
ON DELETE CASCADE
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Calendars_Projects]') AND parent_object_id = OBJECT_ID(N'[dbo].[Calendars]'))
ALTER TABLE [dbo].[Calendars] NOCHECK CONSTRAINT [FK_Calendars_Projects]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_CalendarWorkingHours_Calendars1]') AND parent_object_id = OBJECT_ID(N'[dbo].[CalendarWorkingHours]'))
ALTER TABLE [dbo].[CalendarWorkingHours]  WITH NOCHECK ADD  CONSTRAINT [FK_CalendarWorkingHours_Calendars1] FOREIGN KEY([CalendarKey])
REFERENCES [dbo].[Calendars] ([ItemKey])
ON UPDATE CASCADE
ON DELETE CASCADE
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_CalendarWorkingHours_Calendars1]') AND parent_object_id = OBJECT_ID(N'[dbo].[CalendarWorkingHours]'))
ALTER TABLE [dbo].[CalendarWorkingHours] CHECK CONSTRAINT [FK_CalendarWorkingHours_Calendars1]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Groups_Projects]') AND parent_object_id = OBJECT_ID(N'[dbo].[Groups]'))
ALTER TABLE [dbo].[Groups]  WITH CHECK ADD  CONSTRAINT [FK_Groups_Projects] FOREIGN KEY([ProjectKey])
REFERENCES [dbo].[Projects] ([ItemKey])
ON UPDATE CASCADE
ON DELETE CASCADE
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Groups_Projects]') AND parent_object_id = OBJECT_ID(N'[dbo].[Groups]'))
ALTER TABLE [dbo].[Groups] CHECK CONSTRAINT [FK_Groups_Projects]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ItemUserData_Projects]') AND parent_object_id = OBJECT_ID(N'[dbo].[ItemUserData]'))
ALTER TABLE [dbo].[ItemUserData]  WITH CHECK ADD  CONSTRAINT [FK_ItemUserData_Projects] FOREIGN KEY([ProjectKey])
REFERENCES [dbo].[Projects] ([ItemKey])
ON UPDATE CASCADE
ON DELETE CASCADE
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ItemUserData_Projects]') AND parent_object_id = OBJECT_ID(N'[dbo].[ItemUserData]'))
ALTER TABLE [dbo].[ItemUserData] CHECK CONSTRAINT [FK_ItemUserData_Projects]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ProjectBaselineItems_ProjectBaselines]') AND parent_object_id = OBJECT_ID(N'[dbo].[ProjectBaselineData]'))
ALTER TABLE [dbo].[ProjectBaselineData]  WITH CHECK ADD  CONSTRAINT [FK_ProjectBaselineItems_ProjectBaselines] FOREIGN KEY([BaselineKey])
REFERENCES [dbo].[ProjectBaselines] ([ItemKey])
ON UPDATE CASCADE
ON DELETE CASCADE
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ProjectBaselineItems_ProjectBaselines]') AND parent_object_id = OBJECT_ID(N'[dbo].[ProjectBaselineData]'))
ALTER TABLE [dbo].[ProjectBaselineData] CHECK CONSTRAINT [FK_ProjectBaselineItems_ProjectBaselines]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ProjectBaselines_Projects]') AND parent_object_id = OBJECT_ID(N'[dbo].[ProjectBaselines]'))
ALTER TABLE [dbo].[ProjectBaselines]  WITH CHECK ADD  CONSTRAINT [FK_ProjectBaselines_Projects] FOREIGN KEY([ProjectKey])
REFERENCES [dbo].[Projects] ([ItemKey])
ON UPDATE CASCADE
ON DELETE CASCADE
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ProjectBaselines_Projects]') AND parent_object_id = OBJECT_ID(N'[dbo].[ProjectBaselines]'))
ALTER TABLE [dbo].[ProjectBaselines] CHECK CONSTRAINT [FK_ProjectBaselines_Projects]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ResourceAllocations_Projects]') AND parent_object_id = OBJECT_ID(N'[dbo].[ResourceAllocations]'))
ALTER TABLE [dbo].[ResourceAllocations]  WITH CHECK ADD  CONSTRAINT [FK_ResourceAllocations_Projects] FOREIGN KEY([ProjectKey])
REFERENCES [dbo].[Projects] ([ItemKey])
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ResourceAllocations_Projects]') AND parent_object_id = OBJECT_ID(N'[dbo].[ResourceAllocations]'))
ALTER TABLE [dbo].[ResourceAllocations] CHECK CONSTRAINT [FK_ResourceAllocations_Projects]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ResourceAllocations_Resources]') AND parent_object_id = OBJECT_ID(N'[dbo].[ResourceAllocations]'))
ALTER TABLE [dbo].[ResourceAllocations]  WITH CHECK ADD  CONSTRAINT [FK_ResourceAllocations_Resources] FOREIGN KEY([ResourceKey])
REFERENCES [dbo].[Resources] ([ItemKey])
ON UPDATE CASCADE
ON DELETE CASCADE
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ResourceAllocations_Resources]') AND parent_object_id = OBJECT_ID(N'[dbo].[ResourceAllocations]'))
ALTER TABLE [dbo].[ResourceAllocations] CHECK CONSTRAINT [FK_ResourceAllocations_Resources]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ResourceAllocations_Tasks]') AND parent_object_id = OBJECT_ID(N'[dbo].[ResourceAllocations]'))
ALTER TABLE [dbo].[ResourceAllocations]  WITH CHECK ADD  CONSTRAINT [FK_ResourceAllocations_Tasks] FOREIGN KEY([TaskKey])
REFERENCES [dbo].[Tasks] ([ItemKey])
ON UPDATE CASCADE
ON DELETE CASCADE
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ResourceAllocations_Tasks]') AND parent_object_id = OBJECT_ID(N'[dbo].[ResourceAllocations]'))
ALTER TABLE [dbo].[ResourceAllocations] CHECK CONSTRAINT [FK_ResourceAllocations_Tasks]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ResourceRelations_Resources]') AND parent_object_id = OBJECT_ID(N'[dbo].[ResourceRelations]'))
ALTER TABLE [dbo].[ResourceRelations]  WITH CHECK ADD  CONSTRAINT [FK_ResourceRelations_Resources] FOREIGN KEY([ResourceKey])
REFERENCES [dbo].[Resources] ([ItemKey])
ON UPDATE CASCADE
ON DELETE CASCADE
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ResourceRelations_Resources]') AND parent_object_id = OBJECT_ID(N'[dbo].[ResourceRelations]'))
ALTER TABLE [dbo].[ResourceRelations] CHECK CONSTRAINT [FK_ResourceRelations_Resources]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ResourceRelations_Tasks]') AND parent_object_id = OBJECT_ID(N'[dbo].[ResourceRelations]'))
ALTER TABLE [dbo].[ResourceRelations]  WITH CHECK ADD  CONSTRAINT [FK_ResourceRelations_Tasks] FOREIGN KEY([TaskKey])
REFERENCES [dbo].[Tasks] ([ItemKey])
ON UPDATE CASCADE
ON DELETE CASCADE
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ResourceRelations_Tasks]') AND parent_object_id = OBJECT_ID(N'[dbo].[ResourceRelations]'))
ALTER TABLE [dbo].[ResourceRelations] CHECK CONSTRAINT [FK_ResourceRelations_Tasks]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Resources_Projects]') AND parent_object_id = OBJECT_ID(N'[dbo].[Resources]'))
ALTER TABLE [dbo].[Resources]  WITH NOCHECK ADD  CONSTRAINT [FK_Resources_Projects] FOREIGN KEY([ProjectKey])
REFERENCES [dbo].[Projects] ([ItemKey])
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Resources_Projects]') AND parent_object_id = OBJECT_ID(N'[dbo].[Resources]'))
ALTER TABLE [dbo].[Resources] CHECK CONSTRAINT [FK_Resources_Projects]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ResourceSkills_Resources]') AND parent_object_id = OBJECT_ID(N'[dbo].[ResourceSkills]'))
ALTER TABLE [dbo].[ResourceSkills]  WITH CHECK ADD  CONSTRAINT [FK_ResourceSkills_Resources] FOREIGN KEY([ResourceKey])
REFERENCES [dbo].[Resources] ([ItemKey])
ON UPDATE CASCADE
ON DELETE CASCADE
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ResourceSkills_Resources]') AND parent_object_id = OBJECT_ID(N'[dbo].[ResourceSkills]'))
ALTER TABLE [dbo].[ResourceSkills] CHECK CONSTRAINT [FK_ResourceSkills_Resources]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ResourceSkills_Skills]') AND parent_object_id = OBJECT_ID(N'[dbo].[ResourceSkills]'))
ALTER TABLE [dbo].[ResourceSkills]  WITH CHECK ADD  CONSTRAINT [FK_ResourceSkills_Skills] FOREIGN KEY([SkillKey])
REFERENCES [dbo].[Skills] ([ItemKey])
ON UPDATE CASCADE
ON DELETE CASCADE
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ResourceSkills_Skills]') AND parent_object_id = OBJECT_ID(N'[dbo].[ResourceSkills]'))
ALTER TABLE [dbo].[ResourceSkills] CHECK CONSTRAINT [FK_ResourceSkills_Skills]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Skills_Projects]') AND parent_object_id = OBJECT_ID(N'[dbo].[Skills]'))
ALTER TABLE [dbo].[Skills]  WITH CHECK ADD  CONSTRAINT [FK_Skills_Projects] FOREIGN KEY([ProjectKey])
REFERENCES [dbo].[Projects] ([ItemKey])
ON UPDATE CASCADE
ON DELETE CASCADE
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Skills_Projects]') AND parent_object_id = OBJECT_ID(N'[dbo].[Skills]'))
ALTER TABLE [dbo].[Skills] CHECK CONSTRAINT [FK_Skills_Projects]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TaskRelations_Tasks]') AND parent_object_id = OBJECT_ID(N'[dbo].[TaskRelations]'))
ALTER TABLE [dbo].[TaskRelations]  WITH CHECK ADD  CONSTRAINT [FK_TaskRelations_Tasks] FOREIGN KEY([TaskKey])
REFERENCES [dbo].[Tasks] ([ItemKey])
ON UPDATE CASCADE
ON DELETE CASCADE
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TaskRelations_Tasks]') AND parent_object_id = OBJECT_ID(N'[dbo].[TaskRelations]'))
ALTER TABLE [dbo].[TaskRelations] CHECK CONSTRAINT [FK_TaskRelations_Tasks]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TaskRelations_Tasks1]') AND parent_object_id = OBJECT_ID(N'[dbo].[TaskRelations]'))
ALTER TABLE [dbo].[TaskRelations]  WITH NOCHECK ADD  CONSTRAINT [FK_TaskRelations_Tasks1] FOREIGN KEY([DependingTaskKey])
REFERENCES [dbo].[Tasks] ([ItemKey])
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TaskRelations_Tasks1]') AND parent_object_id = OBJECT_ID(N'[dbo].[TaskRelations]'))
ALTER TABLE [dbo].[TaskRelations] NOCHECK CONSTRAINT [FK_TaskRelations_Tasks1]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Tasks_Projects]') AND parent_object_id = OBJECT_ID(N'[dbo].[Tasks]'))
ALTER TABLE [dbo].[Tasks]  WITH CHECK ADD  CONSTRAINT [FK_Tasks_Projects] FOREIGN KEY([ProjectKey])
REFERENCES [dbo].[Projects] ([ItemKey])
ON UPDATE CASCADE
ON DELETE CASCADE
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Tasks_Projects]') AND parent_object_id = OBJECT_ID(N'[dbo].[Tasks]'))
ALTER TABLE [dbo].[Tasks] CHECK CONSTRAINT [FK_Tasks_Projects]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_WorkPreferredResources_Resources]') AND parent_object_id = OBJECT_ID(N'[dbo].[WorkPreferredResources]'))
ALTER TABLE [dbo].[WorkPreferredResources]  WITH CHECK ADD  CONSTRAINT [FK_WorkPreferredResources_Resources] FOREIGN KEY([ResourceKey])
REFERENCES [dbo].[Resources] ([ItemKey])
ON UPDATE CASCADE
ON DELETE CASCADE
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_WorkPreferredResources_Resources]') AND parent_object_id = OBJECT_ID(N'[dbo].[WorkPreferredResources]'))
ALTER TABLE [dbo].[WorkPreferredResources] CHECK CONSTRAINT [FK_WorkPreferredResources_Resources]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_WorkPreferredResources_Works]') AND parent_object_id = OBJECT_ID(N'[dbo].[WorkPreferredResources]'))
ALTER TABLE [dbo].[WorkPreferredResources]  WITH CHECK ADD  CONSTRAINT [FK_WorkPreferredResources_Works] FOREIGN KEY([WorkKey])
REFERENCES [dbo].[Works] ([ItemKey])
ON UPDATE CASCADE
ON DELETE CASCADE
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_WorkPreferredResources_Works]') AND parent_object_id = OBJECT_ID(N'[dbo].[WorkPreferredResources]'))
ALTER TABLE [dbo].[WorkPreferredResources] CHECK CONSTRAINT [FK_WorkPreferredResources_Works]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Works_Projects]') AND parent_object_id = OBJECT_ID(N'[dbo].[Works]'))
ALTER TABLE [dbo].[Works]  WITH CHECK ADD  CONSTRAINT [FK_Works_Projects] FOREIGN KEY([ProjectKey])
REFERENCES [dbo].[Projects] ([ItemKey])
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Works_Projects]') AND parent_object_id = OBJECT_ID(N'[dbo].[Works]'))
ALTER TABLE [dbo].[Works] CHECK CONSTRAINT [FK_Works_Projects]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Works_Skills]') AND parent_object_id = OBJECT_ID(N'[dbo].[Works]'))
ALTER TABLE [dbo].[Works]  WITH CHECK ADD  CONSTRAINT [FK_Works_Skills] FOREIGN KEY([SkillKey])
REFERENCES [dbo].[Skills] ([ItemKey])
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Works_Skills]') AND parent_object_id = OBJECT_ID(N'[dbo].[Works]'))
ALTER TABLE [dbo].[Works] CHECK CONSTRAINT [FK_Works_Skills]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Works_Tasks]') AND parent_object_id = OBJECT_ID(N'[dbo].[Works]'))
ALTER TABLE [dbo].[Works]  WITH CHECK ADD  CONSTRAINT [FK_Works_Tasks] FOREIGN KEY([TaskKey])
REFERENCES [dbo].[Tasks] ([ItemKey])
ON UPDATE CASCADE
ON DELETE CASCADE
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Works_Tasks]') AND parent_object_id = OBJECT_ID(N'[dbo].[Works]'))
ALTER TABLE [dbo].[Works] CHECK CONSTRAINT [FK_Works_Tasks]
GO
IF NOT EXISTS (SELECT * FROM sys.check_constraints WHERE object_id = OBJECT_ID(N'[dbo].[CK_TaskRelations]') AND parent_object_id = OBJECT_ID(N'[dbo].[TaskRelations]'))
ALTER TABLE [dbo].[TaskRelations]  WITH CHECK ADD  CONSTRAINT [CK_TaskRelations] CHECK  (([TaskKey]<>[DependingTaskKey]))
GO
IF  EXISTS (SELECT * FROM sys.check_constraints WHERE object_id = OBJECT_ID(N'[dbo].[CK_TaskRelations]') AND parent_object_id = OBJECT_ID(N'[dbo].[TaskRelations]'))
ALTER TABLE [dbo].[TaskRelations] CHECK CONSTRAINT [CK_TaskRelations]
GO
/****** Object:  Trigger [dbo].[TRG_UpdateCalendarAvailabilities]    Script Date: 25.02.2015 03:38:03 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N'[dbo].[TRG_UpdateCalendarAvailabilities]'))
EXEC dbo.sp_executesql @statement = N'CREATE TRIGGER [dbo].[TRG_UpdateCalendarAvailabilities]
	On [dbo].[CalendarAvailabilities] For Update
AS
BEGIN
	SET NOCOUNT ON;	
	Update CalendarAvailabilities Set ModifiedDate = GETDATE(), ModifiedUser = USER_NAME(USER_ID()) where AvailabilityKey IN (select AvailabilityKey from inserted)
END
' 
GO
/****** Object:  Trigger [dbo].[TRG_UpdateCalendar]    Script Date: 25.02.2015 03:38:03 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N'[dbo].[TRG_UpdateCalendar]'))
EXEC dbo.sp_executesql @statement = N'CREATE TRIGGER [dbo].[TRG_UpdateCalendar]
	On [dbo].[Calendars] For Update
AS
BEGIN
	SET NOCOUNT ON;	
	Update Calendars Set ModifiedDate = GETDATE(), ModifiedUser = USER_NAME(USER_ID()) where ItemKey IN (select ItemKey from inserted)
END
' 
GO
/****** Object:  Trigger [dbo].[TRG_DeleteGroup]    Script Date: 25.02.2015 03:38:03 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N'[dbo].[TRG_DeleteGroup]'))
EXEC dbo.sp_executesql @statement = N'
CREATE TRIGGER [dbo].[TRG_DeleteGroup]
   ON  [dbo].[Groups]
   AFTER DELETE
AS 
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
	
	Delete FROM dbo.ItemUserData Where dbo.ItemUserData.ItemKey IN (select ItemKey from deleted)	
END

' 
GO
/****** Object:  Trigger [dbo].[TRG_UpdateGroups]    Script Date: 25.02.2015 03:38:03 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N'[dbo].[TRG_UpdateGroups]'))
EXEC dbo.sp_executesql @statement = N'CREATE TRIGGER [dbo].[TRG_UpdateGroups]
	On [dbo].[Groups] For Update
AS
BEGIN
	SET NOCOUNT ON;	
	Update Groups Set ModifiedDate = GETDATE(), ModifiedUser = USER_NAME(USER_ID()) where ItemKey IN (select ItemKey from inserted)
END
' 
GO
/****** Object:  Trigger [dbo].[TRG_ItemImages_Delete]    Script Date: 25.02.2015 03:38:03 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N'[dbo].[TRG_ItemImages_Delete]'))
EXEC dbo.sp_executesql @statement = N'CREATE TRIGGER [dbo].[TRG_ItemImages_Delete]
   ON  [dbo].[ItemImages]
   AFTER DELETE
AS 
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

	Update dbo.Tasks set ImageKey = null Where dbo.Tasks.ImageKey IN (select ImageKey from deleted)
	Update dbo.Resources set ImageKey = null Where dbo.Resources.ImageKey IN (select ImageKey from deleted)
	Update dbo.Groups set ImageKey = null Where dbo.Groups.ImageKey IN (select ImageKey from deleted)
END
' 
GO
/****** Object:  Trigger [dbo].[TRG_UpdateProjectBaselines]    Script Date: 25.02.2015 03:38:03 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N'[dbo].[TRG_UpdateProjectBaselines]'))
EXEC dbo.sp_executesql @statement = N'CREATE TRIGGER [dbo].[TRG_UpdateProjectBaselines]
	On [dbo].[ProjectBaselines] For Update
AS
BEGIN
	SET NOCOUNT ON;	
	Update ProjectBaselines Set ModifiedDate = GETDATE(), ModifiedUser = USER_NAME(USER_ID()) where ItemKey IN (select ItemKey from inserted)
END
' 
GO
/****** Object:  Trigger [dbo].[TRG_UpdateProjects]    Script Date: 25.02.2015 03:38:03 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N'[dbo].[TRG_UpdateProjects]'))
EXEC dbo.sp_executesql @statement = N'CREATE TRIGGER [dbo].[TRG_UpdateProjects]
	On [dbo].[Projects] For Update
AS
BEGIN
	SET NOCOUNT ON;	
	Update Projects Set ModifiedDate = GETDATE(), ModifiedUser = USER_NAME(USER_ID()) where ItemKey IN (select ItemKey from inserted)
END
' 
GO
/****** Object:  Trigger [dbo].[TRG_DeleteResource]    Script Date: 25.02.2015 03:38:03 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N'[dbo].[TRG_DeleteResource]'))
EXEC dbo.sp_executesql @statement = N'
CREATE TRIGGER [dbo].[TRG_DeleteResource]
   ON  [dbo].[Resources]
   AFTER DELETE
AS 
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
	
	Delete FROM dbo.ItemUserData Where dbo.ItemUserData.ItemKey IN (select ItemKey from deleted)	
END

' 
GO
/****** Object:  Trigger [dbo].[TRG_UpdateResources]    Script Date: 25.02.2015 03:38:03 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N'[dbo].[TRG_UpdateResources]'))
EXEC dbo.sp_executesql @statement = N'CREATE TRIGGER [dbo].[TRG_UpdateResources]
	On [dbo].[Resources] For Update
AS
BEGIN
	SET NOCOUNT ON;	
	Update Resources Set ModifiedDate = GETDATE(), ModifiedUser = USER_NAME(USER_ID()) where ItemKey IN (select ItemKey from inserted)
END
' 
GO
/****** Object:  Trigger [dbo].[TRG_UpdateSkills]    Script Date: 25.02.2015 03:38:03 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N'[dbo].[TRG_UpdateSkills]'))
EXEC dbo.sp_executesql @statement = N'CREATE TRIGGER [dbo].[TRG_UpdateSkills]
	On [dbo].[Skills] For Update
AS
BEGIN
	SET NOCOUNT ON;	
	Update Skills Set ModifiedDate = GETDATE(), ModifiedUser = USER_NAME(USER_ID()) where ItemKey IN (select ItemKey from inserted)
END
' 
GO
/****** Object:  Trigger [dbo].[TRG_DeleteTask]    Script Date: 25.02.2015 03:38:03 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N'[dbo].[TRG_DeleteTask]'))
EXEC dbo.sp_executesql @statement = N'CREATE TRIGGER [dbo].[TRG_DeleteTask]
   ON  [dbo].[Tasks]
   AFTER DELETE
AS 
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
	
	Delete FROM dbo.ItemUserData Where dbo.ItemUserData.ItemKey IN (select ItemKey from deleted)	
END
' 
GO
/****** Object:  Trigger [dbo].[TRG_Tasks_TaskRelations_DependingTask]    Script Date: 25.02.2015 03:38:03 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N'[dbo].[TRG_Tasks_TaskRelations_DependingTask]'))
EXEC dbo.sp_executesql @statement = N'CREATE TRIGGER [dbo].[TRG_Tasks_TaskRelations_DependingTask]
   ON  [dbo].[Tasks]
   AFTER DELETE
AS 
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete From dbo.TaskRelations Where TaskRelations.DependingTaskKey IN (select itemkey from deleted)		

    -- Insert statements for trigger here

END
' 
GO
/****** Object:  Trigger [dbo].[TRG_UpdateTasks]    Script Date: 25.02.2015 03:38:03 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N'[dbo].[TRG_UpdateTasks]'))
EXEC dbo.sp_executesql @statement = N'CREATE TRIGGER [dbo].[TRG_UpdateTasks]
	On [dbo].[Tasks] For Update
AS
BEGIN
	SET NOCOUNT ON;	
	Update Tasks Set ModifiedDate = GETDATE(), ModifiedUser = USER_NAME(USER_ID()) where ItemKey IN (select ItemKey from inserted)
END
' 
GO

if not exists(select SettingsKey from GlobalStringSettings where SettingsKey = '_DbVersion') 
insert into dbo.GlobalStringSettings (SettingsKey, SettingsValue) values ('_DbVersion', '5.0.0')
GO