错误
引用的表中没有主键或候选键 'dbo.CMS_User'匹配外部的引用列列表 键'FK_CMS_UserSettings_User
查询:
ALTER TABLE [dbo].[CMS_UserSettings] WITH CHECK ADD CONSTRAINT [FK_CMS_UserSettings_UserSettingsUserGUID_CMS_User] FOREIGN KEY([UserSettingsUserGUID])
REFERENCES [dbo].[CMS_User] ([UserGUID])
ON UPDATE CASCADE
GO
ALTER TABLE [dbo].[CMS_UserSettings] CHECK CONSTRAINT [FK_CMS_UserSettings_UserSettingsUserGUID_CMS_User]
GO
我在执行语句时遇到上述错误
你能不能帮助我在这里创建一个约束,在创建它时出了什么问题?
CREATE TABLE [dbo].[CMS_UserSettings](
[UserSettingsID] [int] IDENTITY(1,1) NOT NULL,
[UserNickName] [nvarchar](200) NULL,
[UserPicture] [nvarchar](200) NULL,
[UserSignature] [nvarchar](max) NULL,
[UserURLReferrer] [nvarchar](450) NULL,
[UserCampaign] [nvarchar](200) NULL,
[UserMessagingNotificationEmail] [nvarchar](200) NULL,
[UserCustomData] [nvarchar](max) NULL,
[UserRegistrationInfo] [nvarchar](max) NULL,
[UserPreferences] [nvarchar](max) NULL,
[UserActivationDate] [datetime2](7) NULL,
[UserActivatedByUserID] [int] NULL,
[UserTimeZoneID] [int] NULL,
[UserAvatarID] [int] NULL,
[UserBadgeID] [int] NULL,
[UserActivityPoints] [int] NULL,
[UserForumPosts] [int] NULL,
[UserBlogComments] [int] NULL,
[UserGender] [int] NULL,
[UserDateOfBirth] [datetime2](7) NULL,
[UserMessageBoardPosts] [int] NULL,
[UserSettingsUserGUID] [uniqueidentifier] NOT NULL CONSTRAINT [DEFAULT_CMS_UserSettings_UserSettingsUserGUID] DEFAULT ('00000000-0000-0000-0000-000000000000'),
[UserSettingsUserID] [int] NOT NULL CONSTRAINT [DEFAULT_CMS_UserSettings_UserSettingsUserID] DEFAULT ((0)),
[WindowsLiveID] [nvarchar](50) NULL,
[UserBlogPosts] [int] NULL,
[UserWaitingForApproval] [bit] NULL CONSTRAINT [DEFAULT_CMS_UserSettings_UserWaitingForApproval] DEFAULT ((0)),
[UserDialogsConfiguration] [nvarchar](max) NULL,
[UserDescription] [nvarchar](max) NULL,
[UserUsedWebParts] [nvarchar](1000) NULL,
[UserUsedWidgets] [nvarchar](1000) NULL,
[UserFacebookID] [nvarchar](100) NULL,
[UserAuthenticationGUID] [uniqueidentifier] NULL,
[UserSkype] [nvarchar](100) NULL,
[UserIM] [nvarchar](100) NULL,
[UserPhone] [nvarchar](26) NULL,
[UserPosition] [nvarchar](200) NULL,
[UserLinkedInID] [nvarchar](100) NULL,
[UserLogActivities] [bit] NULL,
[UserPasswordRequestHash] [nvarchar](100) NULL,
[UserInvalidLogOnAttempts] [int] NULL CONSTRAINT [DEFAULT_CMS_UserSettings_UserInvalidLogOnAttempts] DEFAULT ((0)),
[UserInvalidLogOnAttemptsHash] [nvarchar](100) NULL,
[UserAvatarType] [nvarchar](200) NULL,
[UserAccountLockReason] [int] NULL CONSTRAINT [DEFAULT_CMS_UserSettings_UserAccountLockReason] DEFAULT ((0)),
[UserPasswordLastChanged] [datetime2](7) NULL,
[UserDataComUser] [nvarchar](200) NULL,
[UserDataComPassword] [nvarchar](200) NULL,
[UserShowIntroductionTile] [bit] NULL,
[UserDashboardApplications] [nvarchar](max) NULL,
[UserDismissedSmartTips] [nvarchar](max) NULL,
CONSTRAINT [PK_CMS_UserSettings] PRIMARY KEY CLUSTERED
(
[UserSettingsID] 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
ALTER TABLE [dbo].[CMS_UserSettings] WITH CHECK ADD CONSTRAINT [FK_CMS_UserSettings_UserActivatedByUserID_CMS_User] FOREIGN KEY([UserActivatedByUserID])
REFERENCES [dbo].[CMS_User] ([UserID])
GO
ALTER TABLE [dbo].[CMS_UserSettings] CHECK CONSTRAINT [FK_CMS_UserSettings_UserActivatedByUserID_CMS_User]
GO
ALTER TABLE [dbo].[CMS_UserSettings] WITH CHECK ADD CONSTRAINT [FK_CMS_UserSettings_UserAvatarID_CMS_Avatar] FOREIGN KEY([UserAvatarID])
REFERENCES [dbo].[CMS_Avatar] ([AvatarID])
GO
ALTER TABLE [dbo].[CMS_UserSettings] CHECK CONSTRAINT [FK_CMS_UserSettings_UserAvatarID_CMS_Avatar]
GO
ALTER TABLE [dbo].[CMS_UserSettings] WITH CHECK ADD CONSTRAINT [FK_CMS_UserSettings_UserBadgeID_CMS_Badge] FOREIGN KEY([UserBadgeID])
REFERENCES [dbo].[CMS_Badge] ([BadgeID])
GO
ALTER TABLE [dbo].[CMS_UserSettings] CHECK CONSTRAINT [FK_CMS_UserSettings_UserBadgeID_CMS_Badge]
GO
ALTER TABLE [dbo].[CMS_UserSettings] WITH CHECK ADD CONSTRAINT [FK_CMS_UserSettings_UserSettingsUserGUID_CMS_User] FOREIGN KEY([UserSettingsUserGUID])
REFERENCES [dbo].[CMS_User] ([UserGUID])
ON UPDATE CASCADE
GO
ALTER TABLE [dbo].[CMS_UserSettings] CHECK CONSTRAINT [FK_CMS_UserSettings_UserSettingsUserGUID_CMS_User]
GO
ALTER TABLE [dbo].[CMS_UserSettings] WITH CHECK ADD CONSTRAINT [FK_CMS_UserSettings_UserSettingsUserID_CMS_User] FOREIGN KEY([UserSettingsUserID])
REFERENCES [dbo].[CMS_User] ([UserID])
GO
ALTER TABLE [dbo].[CMS_UserSettings] CHECK CONSTRAINT [FK_CMS_UserSettings_UserSettingsUserID_CMS_User]
GO
ALTER TABLE [dbo].[CMS_UserSettings] WITH CHECK ADD CONSTRAINT [FK_CMS_UserSettings_UserTimeZoneID_CMS_TimeZone] FOREIGN KEY([UserTimeZoneID])
REFERENCES [dbo].[CMS_TimeZone] ([TimeZoneID])
GO
ALTER TABLE [dbo].[CMS_UserSettings] CHECK CONSTRAINT [FK_CMS_UserSettings_UserTimeZoneID_CMS_TimeZone]
GO
CREATE TABLE [dbo].[CMS_User](
[UserID] [int] IDENTITY(1,1) NOT NULL,
[UserName] [nvarchar](100) NOT NULL CONSTRAINT [DEFAULT_CMS_User_UserName] DEFAULT (''),
[FirstName] [nvarchar](100) NULL,
[MiddleName] [nvarchar](100) NULL,
[LastName] [nvarchar](100) NULL,
[FullName] [nvarchar](450) NULL,
[Email] [nvarchar](254) NULL,
[UserPassword] [nvarchar](100) NOT NULL CONSTRAINT [DEFAULT_CMS_User_UserPassword] DEFAULT (N''),
[PreferredCultureCode] [nvarchar](10) NULL,
[PreferredUICultureCode] [nvarchar](10) NULL,
[UserEnabled] [bit] NOT NULL CONSTRAINT [DEFAULT_CMS_User_UserEnabled] DEFAULT ((0)),
[UserIsExternal] [bit] NULL CONSTRAINT [DEFAULT_CMS_User_UserIsExternal] DEFAULT ((0)),
[UserPasswordFormat] [nvarchar](10) NULL,
[UserCreated] [datetime2](7) NULL,
[LastLogon] [datetime2](7) NULL,
[UserStartingAliasPath] [nvarchar](200) NULL,
[UserGUID] [uniqueidentifier] NOT NULL,
[UserLastModified] [datetime2](7) NOT NULL,
[UserLastLogonInfo] [nvarchar](max) NULL,
[UserIsHidden] [bit] NULL CONSTRAINT [DEFAULT_CMS_User_UserIsHidden] DEFAULT ((0)),
[UserVisibility] [nvarchar](max) NULL,
[UserIsDomain] [bit] NULL CONSTRAINT [DEFAULT_CMS_User_UserIsDomain] DEFAULT ((0)),
[UserHasAllowedCultures] [bit] NULL,
[UserTokenID] [uniqueidentifier] NULL,
[UserMFRequired] [bit] NULL,
[UserTokenIteration] [int] NULL,
[CountryCode] [nvarchar](2) NULL CONSTRAINT [DEFAULT_CMS_User_CountryCode] DEFAULT (N'US'),
[UserPrivilegeLevel] [int] NULL,
[UserSecurityStamp] [nvarchar](72) NULL,
CONSTRAINT [PK_CMS_User] PRIMARY KEY CLUSTERED
(
[UserID] 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