UPDATE [dbo].[Options] SET [OptionValue] = '3.2.0' WHERE [OptionID] = 14
GO

sp_RENAME 'EventLogEntries' , 'MonitoringEventLogs';
GO
sp_RENAME 'MonitoringEventLogs.ServerID' , 'MonitoringServerID', 'COLUMN';
GO

sp_RENAME 'UlsEventEntries' , 'MonitoringUlsEvents';
GO
sp_RENAME 'MonitoringUlsEvents.ServerID' , 'MonitoringServerID', 'COLUMN';
GO

sp_RENAME 'MonitoredServers' , 'MonitoringServers';
GO 
sp_RENAME 'MonitoringServers.ServerName' , 'Name', 'COLUMN';
GO

sp_RENAME 'Licenses' , 'FeatureLicenses';
GO
sp_RENAME 'FeatureLicenses.licenseID' , 'ID', 'COLUMN';
GO
sp_RENAME 'FeatureLicenses.editionID' , 'EditionID', 'COLUMN';
GO
sp_RENAME 'FeatureLicenses.featureID' , 'FeatureID', 'COLUMN';
GO
sp_RENAME 'FeatureLicenses.numberOfLicenses' , 'NumberOfLicenses', 'COLUMN';
GO

DROP TABLE [dbo].[ActivatedFeatures]
GO
DROP TABLE [dbo].[Editions]
GO
DROP TABLE [dbo].[Features]
GO
DROP TABLE [dbo].[Memberships]
GO
DROP TABLE [dbo].[PermissionTypes]
GO
DROP TABLE [dbo].[PolicyLevels]
GO
DROP TABLE [dbo].[PolicyPermissions]
GO
DROP TABLE [dbo].[Principals]
GO
DROP TABLE [dbo].[PrincipalTypes]
GO
DROP TABLE [dbo].[RoleAssignments]
GO
DROP TABLE [dbo].[Roles]
GO
DROP TABLE [dbo].[Scopes]
GO
DROP TABLE [dbo].[SharePointObjects]
GO
DROP TABLE [dbo].[SharePointObjectTypes]
GO
DROP TABLE [dbo].[WebApplicationPermissions]
GO
DROP TABLE [dbo].[WebApplications]
GO
DROP TABLE [dbo].[Zones]
GO
DROP TABLE [dbo].[PermissionGroupType]
GO
DROP TABLE [dbo].[RolePermissions]
GO

/****** Object:  Table [dbo].[DateRanges]    Script Date: 27.2.2013. 13:40:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[DateRanges](
	[DateRangeID] [int] NOT NULL,
	[Name] [nchar](100) NOT NULL,
 CONSTRAINT [PK_SubscriptionDateRange] PRIMARY KEY CLUSTERED 
(
	[DateRangeID] 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].[EmailSubscriptions]    Script Date: 27.2.2013. 13:40:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[EmailSubscriptions](
	[EmailSubscriptionID] [int] IDENTITY(1,1) NOT NULL,
	[Subject] [nvarchar](500) NOT NULL,
	[Body] [nvarchar](4000) NOT NULL,
	[EmailReceiversList] [nvarchar](1000) NOT NULL,
	[LastSentOn] [datetime] NOT NULL,
	[CombineIntoSingleAttachment] [bit] NOT NULL,
 CONSTRAINT [PK_ReportSubscription] PRIMARY KEY CLUSTERED 
(
	[EmailSubscriptionID] 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].[EmalSubscriptionDateRanges]    Script Date: 27.2.2013. 13:40:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[EmalSubscriptionDateRanges](
	[DateRangeID] [int] NOT NULL,
	[EmailSubscriptionID] [int] NOT NULL,
 CONSTRAINT [PK_EmalSubscriptionDateRanges] PRIMARY KEY CLUSTERED 
(
	[DateRangeID] ASC,
	[EmailSubscriptionID] 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

GO
/****** Object:  Table [dbo].[FeatureEditions]    Script Date: 27.2.2013. 13:40:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[FeatureEditions](
	[ID] [int] NOT NULL,
	[Name] [nvarchar](50) NOT NULL,
 CONSTRAINT [PK_Editions] PRIMARY KEY CLUSTERED 
(
	[ID] 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].[Features]    Script Date: 27.2.2013. 13:40:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Features](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[FeatureGuid] [uniqueidentifier] NOT NULL,
	[Title] [nvarchar](255) NOT NULL,
	[ScopeID] [int] NOT NULL,
	[Version] [nvarchar](50) NOT NULL,
	[Custom] [bit] NOT NULL,
	[Solution] [nvarchar](255) NOT NULL,
	[SolutionName] [nvarchar](255) NULL,
	[Hidden] [bit] NOT NULL,
	[EditionID] [int] NULL,
 CONSTRAINT [PK_Features] PRIMARY KEY CLUSTERED 
(
	[ID] 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].[FeaturesActivations]    Script Date: 27.2.2013. 13:40:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[FeaturesActivations](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[LoadingInfoID] [int] NOT NULL,
	[FeatureID] [int] NOT NULL,
	[SPObjectID] [int] NULL,
	[WebApplicationID] [int] NULL,
 CONSTRAINT [PK_FeaturesActivations] PRIMARY KEY CLUSTERED 
(
	[ID] 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].[FeatureScopes]    Script Date: 27.2.2013. 13:40:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[FeatureScopes](
	[ID] [int] NOT NULL,
	[Name] [nvarchar](50) NOT NULL,
 CONSTRAINT [PK_Scopes] PRIMARY KEY CLUSTERED 
(
	[ID] 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

GO
/****** Object:  Table [dbo].[FeaturesLoaded]    Script Date: 27.2.2013. 13:40:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[FeaturesLoaded](
	[FeaturesLoadedID] [int] IDENTITY(1,1) NOT NULL,
	[FeatureID] [int] NOT NULL,
	[LoadingInfoID] [int] NOT NULL,
 CONSTRAINT [PK_FeaturesLoaded] PRIMARY KEY CLUSTERED 
(
	[FeaturesLoadedID] 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

GO
/****** Object:  Table [dbo].[LoadingInfos]    Script Date: 27.2.2013. 13:40:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[LoadingInfos](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[CreatedOn] [datetime] NOT NULL,
	[PermissionsLoaded] [bit] NOT NULL,
	[FeaturesLoaded] [bit] NOT NULL,
	[SiteFeaturesLoaded] [bit] NOT NULL,
	[SubsitesLoaded] [bit] NOT NULL,
	[ListsLoaded] [bit] NOT NULL,
	[ListItemsLoaded] [bit] NOT NULL,
 CONSTRAINT [PK_LoadingInfo] PRIMARY KEY CLUSTERED 
(
	[ID] 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].[PermissionGroupTypes]    Script Date: 27.2.2013. 13:40:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PermissionGroupTypes](
	[PermissionGroupTypeID] [int] NOT NULL,
	[Name] [nvarchar](255) NOT NULL,
 CONSTRAINT [PK_PermissionGroupType] PRIMARY KEY CLUSTERED 
(
	[PermissionGroupTypeID] 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].[PermissionScopes]    Script Date: 27.2.2013. 13:40:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PermissionScopes](
	[ID] [int] IDENTITY(1,1) NOT NULL,
 CONSTRAINT [PK_PermissionScope] PRIMARY KEY CLUSTERED 
(
	[ID] 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].[PermissionTypes]    Script Date: 27.2.2013. 13:40:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PermissionTypes](
	[PermissionTypeID] [int] NOT NULL,
	[Name] [nvarchar](255) NOT NULL,
	[PermissionGroupTypeID] [int] NOT NULL,
 CONSTRAINT [PK_PermissionTypes] PRIMARY KEY CLUSTERED 
(
	[PermissionTypeID] 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].[PolicyLevels]    Script Date: 27.2.2013. 13:40:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PolicyLevels](
	[PolicyLevelID] [int] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](255) NOT NULL,
	[Description] [nvarchar](max) NULL,
	[WebApplicationID] [int] NOT NULL,
 CONSTRAINT [PK_PolicyLevels] PRIMARY KEY CLUSTERED 
(
	[PolicyLevelID] 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]

GO

/****** Object:  Table [dbo].[PolicyPermissions]    Script Date: 27.2.2013. 13:40:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PolicyPermissions](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[LoadingInfoID] [int] NOT NULL,
	[PolicyLevelID] [int] NOT NULL,
	[PermissionTypeID] [int] NOT NULL,
	[Grant] [bit] NOT NULL,
 CONSTRAINT [PK_PolicyPermissions_1] PRIMARY KEY CLUSTERED 
(
	[ID] 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].[PrincipalMemberships]    Script Date: 27.2.2013. 13:40:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PrincipalMemberships](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[LoadingInfoID] [int] NOT NULL,
	[GroupID] [int] NOT NULL,
	[UserID] [int] NOT NULL,
 CONSTRAINT [PK_PrincipalMemberships] PRIMARY KEY CLUSTERED 
(
	[ID] 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

GO
/****** Object:  Table [dbo].[Principals]    Script Date: 27.2.2013. 13:40:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Principals](
	[PrincipalID] [int] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](max) NOT NULL,
	[PrincipalTypeID] [int] NOT NULL,
	[SiteID] [int] NULL,
	[DisplayName] [nvarchar](max) NULL,
	[Email] [nvarchar](max) NULL,
	[AccountEnabled] [bit] NOT NULL,
 CONSTRAINT [PK_Principals] PRIMARY KEY CLUSTERED 
(
	[PrincipalID] 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]

GO
/****** Object:  Table [dbo].[PrincipalTypes]    Script Date: 27.2.2013. 13:40:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PrincipalTypes](
	[PrincipalTypeID] [int] NOT NULL,
	[Name] [nvarchar](50) NOT NULL,
 CONSTRAINT [PK_PrincipalTypes] PRIMARY KEY CLUSTERED 
(
	[PrincipalTypeID] 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].[ReportEmailConfigurations]    Script Date: 27.2.2013. 13:40:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ReportEmailConfigurations](
	[ReportEmailConfigurationID] [int] IDENTITY(1,1) NOT NULL,
	[EmailSubscriptionID] [int] NOT NULL,
	[ReportID] [nvarchar](50) NOT NULL,
	[Filters] [xml] NULL,
	[ReportFormat] [int] NOT NULL,
	[Caption] [nvarchar](4000) NULL,
	[ReportViewID] [int] NULL,
	[ViewOverriden] [bit] NULL,
 CONSTRAINT [PK_ReportEmailConfiguration] PRIMARY KEY CLUSTERED 
(
	[ReportEmailConfigurationID] 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]

GO

/****** Object:  Table [dbo].[RoleAssignments]    Script Date: 27.2.2013. 13:40:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[RoleAssignments](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[LoadingInfoID] [int] NOT NULL,
	[ScopeID] [int] NOT NULL,
	[PrincipalID] [int] NOT NULL,
	[RoleID] [int] NOT NULL,
	[SiteID] [int] NOT NULL,
 CONSTRAINT [PK_RoleAssignments_1] PRIMARY KEY CLUSTERED 
(
	[ID] 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].[RolePermissions]    Script Date: 27.2.2013. 13:40:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[RolePermissions](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[LoadingInfoID] [int] NOT NULL,
	[RoleID] [int] NOT NULL,
	[PermissionTypeID] [int] NOT NULL,
 CONSTRAINT [PK_RolePermissions_1] PRIMARY KEY CLUSTERED 
(
	[ID] 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].[Roles]    Script Date: 27.2.2013. 13:40:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Roles](
	[RoleID] [int] IDENTITY(1,1) NOT NULL,
	[Title] [nvarchar](255) NOT NULL,
	[Description] [nvarchar](max) NULL,
	[SiteID] [int] NOT NULL,
 CONSTRAINT [PK_Roles] PRIMARY KEY CLUSTERED 
(
	[RoleID] 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]

GO

/****** Object:  Table [dbo].[ScopeAssignments]    Script Date: 27.2.2013. 13:40:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ScopeAssignments](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[LoadingInfoID] [int] NOT NULL,
	[ScopeID] [int] NOT NULL,
	[SPObjectID] [int] NOT NULL,
 CONSTRAINT [PK_ScopeAssignments] PRIMARY KEY CLUSTERED 
(
	[ID] 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].[SharePointObjectMemberships]    Script Date: 27.2.2013. 13:40:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SharePointObjectMemberships](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[LoadingInfoID] [int] NOT NULL,
	[ParentID] [int] NOT NULL,
	[ChildID] [int] NOT NULL,
 CONSTRAINT [PK_SharePointObjectMemberships] PRIMARY KEY CLUSTERED 
(
	[ID] 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].[SharePointObjects]    Script Date: 27.2.2013. 13:40:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SharePointObjects](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](255) NOT NULL,
	[SPObjectTypeID] [int] NOT NULL,
	[SPSiteGuid] [uniqueidentifier] NOT NULL,
	[SPGuid] [uniqueidentifier] NOT NULL,
	[IsRootWeb] [bit] NOT NULL,
	[WebAppID] [int] NOT NULL,
	[HasUniqueRoleAssignments] [bit] NOT NULL,
	[Url] [nvarchar](255) NOT NULL,
	[SiteID] [int] NOT NULL,
 CONSTRAINT [PK_SharePointObjects] PRIMARY KEY CLUSTERED 
(
	[ID] 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].[SharePointObjectTypes]    Script Date: 27.2.2013. 13:40:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SharePointObjectTypes](
	[ID] [int] NOT NULL,
	[Name] [nvarchar](255) NOT NULL,
 CONSTRAINT [PK_SharePointObjectTypes] PRIMARY KEY CLUSTERED 
(
	[ID] 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].[WebApplicationPermissions]    Script Date: 27.2.2013. 13:40:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[WebApplicationPermissions](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[LoadingInfoID] [int] NOT NULL,
	[WebApplicationID] [int] NOT NULL,
	[PrincipalID] [int] NOT NULL,
	[PolicyLevelID] [int] NOT NULL,
	[ZoneID] [int] NOT NULL,
 CONSTRAINT [PK_WebApplicationPermissions_1] PRIMARY KEY CLUSTERED 
(
	[ID] 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].[WebApplications]    Script Date: 27.2.2013. 13:40:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[WebApplications](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](255) NOT NULL,
	[SPGuid] [uniqueidentifier] NOT NULL,
 CONSTRAINT [PK_WebApplications] PRIMARY KEY CLUSTERED 
(
	[ID] 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].[WebApplicationZones]    Script Date: 27.2.2013. 13:40:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[WebApplicationZones](
	[ZoneID] [int] NOT NULL,
	[ZoneName] [nvarchar](255) NOT NULL,
 CONSTRAINT [PK_Zones] PRIMARY KEY CLUSTERED 
(
	[ZoneID] 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].[SiteCollectionAdministrators]    Script Date: 15.3.2013. 15:00:28 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SiteCollectionAdministrators](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[SharePointObjectID] [int] NOT NULL,
	[PrincipalID] [int] NOT NULL,
	[LoadingInfoID] [int] NOT NULL,
	[IsPrimary] [bit] NOT NULL,
 CONSTRAINT [PK_SiteCollectionAdministrators] PRIMARY KEY CLUSTERED 
(
	[ID] 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

INSERT INTO PrincipalTypes (PrincipalTypeID, Name) VALUES (1, 'SharePoint Group')
INSERT INTO PrincipalTypes (PrincipalTypeID, Name) VALUES (2, 'User')
INSERT INTO PrincipalTypes (PrincipalTypeID, Name) VALUES (3, 'Active Directory Group')

INSERT INTO SharePointObjectTypes (ID, Name) VALUES (1, 'Site Collection')
INSERT INTO SharePointObjectTypes (ID, Name) VALUES (2, 'Site')
INSERT INTO SharePointObjectTypes (ID, Name) VALUES (3, 'List')
INSERT INTO SharePointObjectTypes (ID, Name) VALUES (4, 'List Item')

INSERT INTO PermissionGroupTypes (PermissionGroupTypeID, Name) VALUES (0, 'Unknown Permissions')
INSERT INTO PermissionGroupTypes (PermissionGroupTypeID, Name) VALUES (1, 'List Permissions')
INSERT INTO PermissionGroupTypes (PermissionGroupTypeID, Name) VALUES (2, 'Site Permissions')
INSERT INTO PermissionGroupTypes (PermissionGroupTypeID, Name) VALUES (3, 'Personal Permissions')

INSERT INTO PermissionTypes (PermissionTypeID, Name, PermissionGroupTypeID) VALUES (1, 'View Items', 1)
INSERT INTO PermissionTypes (PermissionTypeID, Name, PermissionGroupTypeID) VALUES (2, 'Add Items', 1)
INSERT INTO PermissionTypes (PermissionTypeID, Name, PermissionGroupTypeID) VALUES (3, 'Edit Items', 1)
INSERT INTO PermissionTypes (PermissionTypeID, Name, PermissionGroupTypeID) VALUES (4, 'Delete Items', 1)
INSERT INTO PermissionTypes (PermissionTypeID, Name, PermissionGroupTypeID) VALUES (5, 'Approve Items', 1)
INSERT INTO PermissionTypes (PermissionTypeID, Name, PermissionGroupTypeID) VALUES (6, 'Open Items', 1)
INSERT INTO PermissionTypes (PermissionTypeID, Name, PermissionGroupTypeID) VALUES (7, 'View Versions', 1)
INSERT INTO PermissionTypes (PermissionTypeID, Name, PermissionGroupTypeID) VALUES (8, 'Delete Versions', 1)
INSERT INTO PermissionTypes (PermissionTypeID, Name, PermissionGroupTypeID) VALUES (9, 'Override Check Out', 1)
INSERT INTO PermissionTypes (PermissionTypeID, Name, PermissionGroupTypeID) VALUES (10, 'Manage Personal Views', 3)
INSERT INTO PermissionTypes (PermissionTypeID, Name, PermissionGroupTypeID) VALUES (11, 'Manage Lists', 1)
INSERT INTO PermissionTypes (PermissionTypeID, Name, PermissionGroupTypeID) VALUES (12, 'View Application Pages', 1)
INSERT INTO PermissionTypes (PermissionTypeID, Name, PermissionGroupTypeID) VALUES (13, 'Open', 2)
INSERT INTO PermissionTypes (PermissionTypeID, Name, PermissionGroupTypeID) VALUES (14, 'View Pages', 2)
INSERT INTO PermissionTypes (PermissionTypeID, Name, PermissionGroupTypeID) VALUES (15, 'Add and Customize Pages', 2)
INSERT INTO PermissionTypes (PermissionTypeID, Name, PermissionGroupTypeID) VALUES (16, 'Apply Themes and Borders', 2)
INSERT INTO PermissionTypes (PermissionTypeID, Name, PermissionGroupTypeID) VALUES (17, 'Apply Style Sheets', 2)
INSERT INTO PermissionTypes (PermissionTypeID, Name, PermissionGroupTypeID) VALUES (18, 'View Web Analytics Data', 2)
INSERT INTO PermissionTypes (PermissionTypeID, Name, PermissionGroupTypeID) VALUES (19, 'Use Self-Service Site Creation', 2)
INSERT INTO PermissionTypes (PermissionTypeID, Name, PermissionGroupTypeID) VALUES (20, 'Create Subsites', 2)
INSERT INTO PermissionTypes (PermissionTypeID, Name, PermissionGroupTypeID) VALUES (21, 'Create Groups', 2)
INSERT INTO PermissionTypes (PermissionTypeID, Name, PermissionGroupTypeID) VALUES (22, 'Manage Permissions', 2)
INSERT INTO PermissionTypes (PermissionTypeID, Name, PermissionGroupTypeID) VALUES (23, 'Browse Directories', 2)
INSERT INTO PermissionTypes (PermissionTypeID, Name, PermissionGroupTypeID) VALUES (24, 'Browse User Information', 2)
INSERT INTO PermissionTypes (PermissionTypeID, Name, PermissionGroupTypeID) VALUES (25, 'Add/Remove Personal Web Parts', 3)
INSERT INTO PermissionTypes (PermissionTypeID, Name, PermissionGroupTypeID) VALUES (26, 'Update Personal Web Parts', 3)
INSERT INTO PermissionTypes (PermissionTypeID, Name, PermissionGroupTypeID) VALUES (27, 'Manage Web Site', 2)
INSERT INTO PermissionTypes (PermissionTypeID, Name, PermissionGroupTypeID) VALUES (28, 'Use Client Integration Features', 2)
INSERT INTO PermissionTypes (PermissionTypeID, Name, PermissionGroupTypeID) VALUES (29, 'Use Remote Inerfaces', 2)
INSERT INTO PermissionTypes (PermissionTypeID, Name, PermissionGroupTypeID) VALUES (30, 'Manage Alerts', 2)
INSERT INTO PermissionTypes (PermissionTypeID, Name, PermissionGroupTypeID) VALUES (31, 'Create Alerts', 1)
INSERT INTO PermissionTypes (PermissionTypeID, Name, PermissionGroupTypeID) VALUES (32, 'Edit Personal User Information', 2)
INSERT INTO PermissionTypes (PermissionTypeID, Name, PermissionGroupTypeID) VALUES (33, 'Enumerate Permissions', 2)
INSERT INTO PermissionTypes (PermissionTypeID, Name, PermissionGroupTypeID) VALUES (34, 'Anonymous Search Access List', 0)
INSERT INTO PermissionTypes (PermissionTypeID, Name, PermissionGroupTypeID) VALUES (35, 'Anonymous Search Access Web Lists ', 0)

INSERT INTO WebApplicationZones (ZoneID, ZoneName) VALUES (0, 'Deafult')
INSERT INTO WebApplicationZones (ZoneID, ZoneName) VALUES (1, 'Intranet')
INSERT INTO WebApplicationZones (ZoneID, ZoneName) VALUES (2, 'Internet')
INSERT INTO WebApplicationZones (ZoneID, ZoneName) VALUES (3, 'Custom')
INSERT INTO WebApplicationZones (ZoneID, ZoneName) VALUES (4, 'Extranet')
INSERT INTO WebApplicationZones (ZoneID, ZoneName) VALUES (5, '(All Zones)')

INSERT INTO FeatureScopes (ID, Name) VALUES (0, 'Farm')
INSERT INTO FeatureScopes (ID, Name) VALUES (1, 'Web Application')
INSERT INTO FeatureScopes (ID, Name) VALUES (2, 'Site')
INSERT INTO FeatureScopes (ID, Name) VALUES (3, 'Web')

INSERT INTO FeatureEditions (ID, Name) VALUES (10, 'Foundation')
INSERT INTO FeatureEditions (ID, Name) VALUES (20, 'Standard')
INSERT INTO FeatureEditions (ID, Name) VALUES (30, 'Enterprise')

INSERT INTO DateRanges(DateRangeID, Name) VALUES(1, 'No schedule (sent on demand)');
INSERT INTO DateRanges(DateRangeID, Name) VALUES(2, 'Daily');
INSERT INTO DateRanges(DateRangeID, Name) VALUES(3, 'Weekly');
INSERT INTO DateRanges(DateRangeID, Name) VALUES(4, 'Monthly');
INSERT INTO DateRanges(DateRangeID, Name) VALUES(5, 'Quarterly');
GO


ALTER TABLE [dbo].[PolicyPermissions] ADD  CONSTRAINT [DF_PolicyPermissions_Grant]  DEFAULT ((1)) FOR [Grant]
GO
ALTER TABLE [dbo].[Principals] ADD  DEFAULT ((1)) FOR [AccountEnabled]
GO
ALTER TABLE [dbo].[SharePointObjects] ADD  CONSTRAINT [DF_SharePointObjects_IsRootWeb]  DEFAULT ((0)) FOR [IsRootWeb]
GO
ALTER TABLE [dbo].[SharePointObjects] ADD  CONSTRAINT [DF_SharePointObjects_HasUniqueRoleAssignments]  DEFAULT ((0)) FOR [HasUniqueRoleAssignments]
GO

ALTER TABLE [dbo].[EmalSubscriptionDateRanges]  WITH CHECK ADD  CONSTRAINT [FK_EmalSubscriptionDateRanges_DateRanges] FOREIGN KEY([DateRangeID])
REFERENCES [dbo].[DateRanges] ([DateRangeID])
GO
ALTER TABLE [dbo].[EmalSubscriptionDateRanges] CHECK CONSTRAINT [FK_EmalSubscriptionDateRanges_DateRanges]
GO

ALTER TABLE [dbo].[EmalSubscriptionDateRanges]  WITH CHECK ADD  CONSTRAINT [FK_EmalSubscriptionDateRanges_EmailSubscriptions] FOREIGN KEY([EmailSubscriptionID])
REFERENCES [dbo].[EmailSubscriptions] ([EmailSubscriptionID])
GO
ALTER TABLE [dbo].[EmalSubscriptionDateRanges] CHECK CONSTRAINT [FK_EmalSubscriptionDateRanges_EmailSubscriptions]
GO

ALTER TABLE [dbo].[FeatureLicenses] WITH CHECK ADD  CONSTRAINT [FK_FeatureLicenses_FeatureEditions] FOREIGN KEY([EditionID])
REFERENCES [dbo].[FeatureEditions] ([ID])
GO
ALTER TABLE [dbo].[FeatureLicenses] CHECK CONSTRAINT [FK_FeatureLicenses_FeatureEditions]
GO


ALTER TABLE [dbo].[Features]  WITH CHECK ADD  CONSTRAINT [FK_Features_FeatureEditions] FOREIGN KEY([EditionID])
REFERENCES [dbo].[FeatureEditions] ([ID])
GO
ALTER TABLE [dbo].[Features] CHECK CONSTRAINT [FK_Features_FeatureEditions]
GO

ALTER TABLE [dbo].[Features]  WITH CHECK ADD  CONSTRAINT [FK_Features_FeatureScopes] FOREIGN KEY([ScopeID])
REFERENCES [dbo].[FeatureScopes] ([ID])
GO
ALTER TABLE [dbo].[Features] CHECK CONSTRAINT [FK_Features_FeatureScopes]
GO

ALTER TABLE [dbo].[FeaturesActivations]  WITH CHECK ADD  CONSTRAINT [FK_FeaturesActivations_Features] FOREIGN KEY([FeatureID])
REFERENCES [dbo].[Features] ([ID])
GO
ALTER TABLE [dbo].[FeaturesActivations] CHECK CONSTRAINT [FK_FeaturesActivations_Features]
GO

ALTER TABLE [dbo].[FeaturesActivations]  WITH CHECK ADD  CONSTRAINT [FK_FeaturesActivations_LoadingInfos] FOREIGN KEY([LoadingInfoID])
REFERENCES [dbo].[LoadingInfos] ([ID])
GO
ALTER TABLE [dbo].[FeaturesActivations] CHECK CONSTRAINT [FK_FeaturesActivations_LoadingInfos]
GO

ALTER TABLE [dbo].[FeaturesActivations]  WITH CHECK ADD  CONSTRAINT [FK_FeaturesActivations_SharePointObjects] FOREIGN KEY([SPObjectID])
REFERENCES [dbo].[SharePointObjects] ([ID])
GO
ALTER TABLE [dbo].[FeaturesActivations] CHECK CONSTRAINT [FK_FeaturesActivations_SharePointObjects]
GO

ALTER TABLE [dbo].[FeaturesActivations]  WITH CHECK ADD  CONSTRAINT [FK_FeaturesActivations_WebApplications] FOREIGN KEY([WebApplicationID])
REFERENCES [dbo].[WebApplications] ([ID])
GO
ALTER TABLE [dbo].[FeaturesActivations] CHECK CONSTRAINT [FK_FeaturesActivations_WebApplications]
GO
ALTER TABLE [dbo].[FeaturesLoaded]  WITH CHECK ADD  CONSTRAINT [FK_FeaturesLoaded_Features] FOREIGN KEY([FeatureID])
REFERENCES [dbo].[Features] ([ID])
GO
ALTER TABLE [dbo].[FeaturesLoaded] CHECK CONSTRAINT [FK_FeaturesLoaded_Features]
GO
ALTER TABLE [dbo].[FeaturesLoaded]  WITH CHECK ADD  CONSTRAINT [FK_FeaturesLoaded_LoadingInfos] FOREIGN KEY([LoadingInfoID])
REFERENCES [dbo].[LoadingInfos] ([ID])
GO
ALTER TABLE [dbo].[FeaturesLoaded] CHECK CONSTRAINT [FK_FeaturesLoaded_LoadingInfos]
GO
ALTER TABLE [dbo].[MonitoringEventLogs]  WITH CHECK ADD  CONSTRAINT [FK_MonitoringEventLogs_MonitoringServers] FOREIGN KEY([MonitoringServerID])
REFERENCES [dbo].[MonitoringServers] ([ID])
GO
ALTER TABLE [dbo].[MonitoringEventLogs] CHECK CONSTRAINT [FK_MonitoringEventLogs_MonitoringServers]
GO
ALTER TABLE [dbo].[MonitoringUlsEvents]  WITH CHECK ADD  CONSTRAINT [FK_MonitoringUlsEvents_MonitoringServers] FOREIGN KEY([MonitoringServerID])
REFERENCES [dbo].[MonitoringServers] ([ID])
GO
ALTER TABLE [dbo].[MonitoringUlsEvents] CHECK CONSTRAINT [FK_MonitoringUlsEvents_MonitoringServers]
GO
ALTER TABLE [dbo].[PermissionTypes]  WITH CHECK ADD  CONSTRAINT [FK_PermissionTypes_PermissionGroupType] FOREIGN KEY([PermissionGroupTypeID])
REFERENCES [dbo].[PermissionGroupTypes] ([PermissionGroupTypeID])
GO
ALTER TABLE [dbo].[PermissionTypes] CHECK CONSTRAINT [FK_PermissionTypes_PermissionGroupType]
GO
ALTER TABLE [dbo].[PolicyLevels]  WITH CHECK ADD  CONSTRAINT [FK_PolicyLevels_WebApplications] FOREIGN KEY([WebApplicationID])
REFERENCES [dbo].[WebApplications] ([ID])
GO
ALTER TABLE [dbo].[PolicyLevels] CHECK CONSTRAINT [FK_PolicyLevels_WebApplications]
GO
ALTER TABLE [dbo].[PolicyPermissions]  WITH CHECK ADD  CONSTRAINT [FK_PolicyPermissions_LoadingInfo] FOREIGN KEY([LoadingInfoID])
REFERENCES [dbo].[LoadingInfos] ([ID])
GO
ALTER TABLE [dbo].[PolicyPermissions] CHECK CONSTRAINT [FK_PolicyPermissions_LoadingInfo]
GO
ALTER TABLE [dbo].[PolicyPermissions]  WITH CHECK ADD  CONSTRAINT [FK_PolicyPermissions_PermissionTypes] FOREIGN KEY([PermissionTypeID])
REFERENCES [dbo].[PermissionTypes] ([PermissionTypeID])
GO
ALTER TABLE [dbo].[PolicyPermissions] CHECK CONSTRAINT [FK_PolicyPermissions_PermissionTypes]
GO
ALTER TABLE [dbo].[PolicyPermissions]  WITH CHECK ADD  CONSTRAINT [FK_PolicyPermissions_PolicyLevels] FOREIGN KEY([PolicyLevelID])
REFERENCES [dbo].[PolicyLevels] ([PolicyLevelID])
GO
ALTER TABLE [dbo].[PolicyPermissions] CHECK CONSTRAINT [FK_PolicyPermissions_PolicyLevels]
GO
ALTER TABLE [dbo].[PrincipalMemberships]  WITH CHECK ADD  CONSTRAINT [FK_PrincipalMemberships_LoadingInfos] FOREIGN KEY([LoadingInfoID])
REFERENCES [dbo].[LoadingInfos] ([ID])
GO
ALTER TABLE [dbo].[PrincipalMemberships] CHECK CONSTRAINT [FK_PrincipalMemberships_LoadingInfos]
GO
ALTER TABLE [dbo].[PrincipalMemberships]  WITH CHECK ADD  CONSTRAINT [FK_PrincipalMemberships_Principals] FOREIGN KEY([GroupID])
REFERENCES [dbo].[Principals] ([PrincipalID])
GO
ALTER TABLE [dbo].[PrincipalMemberships] CHECK CONSTRAINT [FK_PrincipalMemberships_Principals]
GO
ALTER TABLE [dbo].[PrincipalMemberships]  WITH CHECK ADD  CONSTRAINT [FK_PrincipalMemberships_Principals1] FOREIGN KEY([UserID])
REFERENCES [dbo].[Principals] ([PrincipalID])
GO
ALTER TABLE [dbo].[PrincipalMemberships] CHECK CONSTRAINT [FK_PrincipalMemberships_Principals1]
GO
ALTER TABLE [dbo].[Principals]  WITH CHECK ADD  CONSTRAINT [FK_Principals_PrincipalTypes] FOREIGN KEY([PrincipalTypeID])
REFERENCES [dbo].[PrincipalTypes] ([PrincipalTypeID])
GO
ALTER TABLE [dbo].[Principals] CHECK CONSTRAINT [FK_Principals_PrincipalTypes]
GO
ALTER TABLE [dbo].[ReportEmailConfigurations]  WITH CHECK ADD  CONSTRAINT [FK_ReportEmailConfigurations_EmailSubscriptions] FOREIGN KEY([EmailSubscriptionID])
REFERENCES [dbo].[EmailSubscriptions] ([EmailSubscriptionID])
GO
ALTER TABLE [dbo].[ReportEmailConfigurations] CHECK CONSTRAINT [FK_ReportEmailConfigurations_EmailSubscriptions]
GO
ALTER TABLE [dbo].[ReportEmailConfigurations]  WITH CHECK ADD  CONSTRAINT [FK_ReportEmailConfigurations_ReportViews] FOREIGN KEY([ReportViewID])
REFERENCES [dbo].[ReportViews] ([ReportViewID])
GO
ALTER TABLE [dbo].[ReportEmailConfigurations] CHECK CONSTRAINT [FK_ReportEmailConfigurations_ReportViews]
GO
ALTER TABLE [dbo].[RoleAssignments]  WITH CHECK ADD  CONSTRAINT [FK_RoleAssignments_LoadingInfo] FOREIGN KEY([LoadingInfoID])
REFERENCES [dbo].[LoadingInfos] ([ID])
GO
ALTER TABLE [dbo].[RoleAssignments] CHECK CONSTRAINT [FK_RoleAssignments_LoadingInfo]
GO
ALTER TABLE [dbo].[RoleAssignments]  WITH CHECK ADD  CONSTRAINT [FK_RoleAssignments_PermissionScope] FOREIGN KEY([ScopeID])
REFERENCES [dbo].[PermissionScopes] ([ID])
GO
ALTER TABLE [dbo].[RoleAssignments] CHECK CONSTRAINT [FK_RoleAssignments_PermissionScope]
GO
ALTER TABLE [dbo].[RoleAssignments]  WITH CHECK ADD  CONSTRAINT [FK_RoleAssignments_Principals] FOREIGN KEY([PrincipalID])
REFERENCES [dbo].[Principals] ([PrincipalID])
GO
ALTER TABLE [dbo].[RoleAssignments] CHECK CONSTRAINT [FK_RoleAssignments_Principals]
GO
ALTER TABLE [dbo].[RoleAssignments]  WITH CHECK ADD  CONSTRAINT [FK_RoleAssignments_Roles] FOREIGN KEY([RoleID])
REFERENCES [dbo].[Roles] ([RoleID])
GO
ALTER TABLE [dbo].[RoleAssignments] CHECK CONSTRAINT [FK_RoleAssignments_Roles]
GO
ALTER TABLE [dbo].[RolePermissions]  WITH CHECK ADD  CONSTRAINT [FK_RolePermissions_LoadingInfo] FOREIGN KEY([LoadingInfoID])
REFERENCES [dbo].[LoadingInfos] ([ID])
GO
ALTER TABLE [dbo].[RolePermissions] CHECK CONSTRAINT [FK_RolePermissions_LoadingInfo]
GO
ALTER TABLE [dbo].[RolePermissions]  WITH CHECK ADD  CONSTRAINT [FK_RolePermissions_PermissionTypes] FOREIGN KEY([PermissionTypeID])
REFERENCES [dbo].[PermissionTypes] ([PermissionTypeID])
GO
ALTER TABLE [dbo].[RolePermissions] CHECK CONSTRAINT [FK_RolePermissions_PermissionTypes]
GO
ALTER TABLE [dbo].[RolePermissions]  WITH CHECK ADD  CONSTRAINT [FK_RolePermissions_Roles] FOREIGN KEY([RoleID])
REFERENCES [dbo].[Roles] ([RoleID])
GO
ALTER TABLE [dbo].[RolePermissions] CHECK CONSTRAINT [FK_RolePermissions_Roles]
GO
ALTER TABLE [dbo].[ScopeAssignments]  WITH CHECK ADD  CONSTRAINT [FK_ScopeAssignments_LoadingInfo] FOREIGN KEY([LoadingInfoID])
REFERENCES [dbo].[LoadingInfos] ([ID])
GO
ALTER TABLE [dbo].[ScopeAssignments] CHECK CONSTRAINT [FK_ScopeAssignments_LoadingInfo]
GO
ALTER TABLE [dbo].[ScopeAssignments]  WITH CHECK ADD  CONSTRAINT [FK_ScopeAssignments_PermissionScope] FOREIGN KEY([ScopeID])
REFERENCES [dbo].[PermissionScopes] ([ID])
GO
ALTER TABLE [dbo].[ScopeAssignments] CHECK CONSTRAINT [FK_ScopeAssignments_PermissionScope]
GO
ALTER TABLE [dbo].[ScopeAssignments]  WITH CHECK ADD  CONSTRAINT [FK_ScopeAssignments_SharePointObjects] FOREIGN KEY([SPObjectID])
REFERENCES [dbo].[SharePointObjects] ([ID])
GO
ALTER TABLE [dbo].[ScopeAssignments] CHECK CONSTRAINT [FK_ScopeAssignments_SharePointObjects]
GO
ALTER TABLE [dbo].[SharePointObjectMemberships]  WITH CHECK ADD  CONSTRAINT [FK_SharePointObjectMemberships_LoadingInfos] FOREIGN KEY([LoadingInfoID])
REFERENCES [dbo].[LoadingInfos] ([ID])
GO
ALTER TABLE [dbo].[SharePointObjectMemberships] CHECK CONSTRAINT [FK_SharePointObjectMemberships_LoadingInfos]
GO
ALTER TABLE [dbo].[SharePointObjectMemberships]  WITH CHECK ADD  CONSTRAINT [FK_SharePointObjectMemberships_SharePointObjects] FOREIGN KEY([ParentID])
REFERENCES [dbo].[SharePointObjects] ([ID])
GO
ALTER TABLE [dbo].[SharePointObjectMemberships] CHECK CONSTRAINT [FK_SharePointObjectMemberships_SharePointObjects]
GO
ALTER TABLE [dbo].[SharePointObjectMemberships]  WITH CHECK ADD  CONSTRAINT [FK_SharePointObjectMemberships_SharePointObjects1] FOREIGN KEY([ChildID])
REFERENCES [dbo].[SharePointObjects] ([ID])
GO
ALTER TABLE [dbo].[SharePointObjectMemberships] CHECK CONSTRAINT [FK_SharePointObjectMemberships_SharePointObjects1]
GO
ALTER TABLE [dbo].[SharePointObjects]  WITH CHECK ADD  CONSTRAINT [FK_SharePointObjects_SharePointObjectTypes] FOREIGN KEY([SPObjectTypeID])
REFERENCES [dbo].[SharePointObjectTypes] ([ID])
GO
ALTER TABLE [dbo].[SharePointObjects] CHECK CONSTRAINT [FK_SharePointObjects_SharePointObjectTypes]
GO
ALTER TABLE [dbo].[WebApplicationPermissions]  WITH CHECK ADD  CONSTRAINT [FK_WebApplicationPermissions_LoadingInfo] FOREIGN KEY([LoadingInfoID])
REFERENCES [dbo].[LoadingInfos] ([ID])
GO
ALTER TABLE [dbo].[WebApplicationPermissions] CHECK CONSTRAINT [FK_WebApplicationPermissions_LoadingInfo]
GO
ALTER TABLE [dbo].[WebApplicationPermissions]  WITH CHECK ADD  CONSTRAINT [FK_WebApplicationPermissions_PolicyLevels] FOREIGN KEY([PolicyLevelID])
REFERENCES [dbo].[PolicyLevels] ([PolicyLevelID])
GO
ALTER TABLE [dbo].[WebApplicationPermissions] CHECK CONSTRAINT [FK_WebApplicationPermissions_PolicyLevels]
GO
ALTER TABLE [dbo].[WebApplicationPermissions]  WITH CHECK ADD  CONSTRAINT [FK_WebApplicationPermissions_Principals] FOREIGN KEY([PrincipalID])
REFERENCES [dbo].[Principals] ([PrincipalID])
GO
ALTER TABLE [dbo].[WebApplicationPermissions] CHECK CONSTRAINT [FK_WebApplicationPermissions_Principals]
GO
ALTER TABLE [dbo].[WebApplicationPermissions]  WITH CHECK ADD  CONSTRAINT [FK_WebApplicationPermissions_WebApplications] FOREIGN KEY([WebApplicationID])
REFERENCES [dbo].[WebApplications] ([ID])
GO
ALTER TABLE [dbo].[WebApplicationPermissions] CHECK CONSTRAINT [FK_WebApplicationPermissions_WebApplications]
GO
ALTER TABLE [dbo].[WebApplicationPermissions]  WITH CHECK ADD  CONSTRAINT [FK_WebApplicationPermissions_Zones] FOREIGN KEY([ZoneID])
REFERENCES [dbo].[WebApplicationZones] ([ZoneID])
GO
ALTER TABLE [dbo].[WebApplicationPermissions] CHECK CONSTRAINT [FK_WebApplicationPermissions_Zones]
GO
ALTER TABLE [dbo].[SiteCollectionAdministrators]  WITH CHECK ADD  CONSTRAINT [FK_SiteCollectionAdministrators_LoadingInfos] FOREIGN KEY([LoadingInfoID])
REFERENCES [dbo].[LoadingInfos] ([ID])
GO
ALTER TABLE [dbo].[SiteCollectionAdministrators] CHECK CONSTRAINT [FK_SiteCollectionAdministrators_LoadingInfos]
GO
ALTER TABLE [dbo].[SiteCollectionAdministrators]  WITH CHECK ADD  CONSTRAINT [FK_SiteCollectionAdministrators_Principals] FOREIGN KEY([PrincipalID])
REFERENCES [dbo].[Principals] ([PrincipalID])
GO
ALTER TABLE [dbo].[SiteCollectionAdministrators] CHECK CONSTRAINT [FK_SiteCollectionAdministrators_Principals]
GO
ALTER TABLE [dbo].[SiteCollectionAdministrators]  WITH CHECK ADD  CONSTRAINT [FK_SiteCollectionAdministrators_SharePointObjects] FOREIGN KEY([SharePointObjectID])
REFERENCES [dbo].[SharePointObjects] ([ID])
GO
ALTER TABLE [dbo].[SiteCollectionAdministrators] CHECK CONSTRAINT [FK_SiteCollectionAdministrators_SharePointObjects]
GO

