【发布时间】:2018-07-18 22:15:47
【问题描述】:
我在创建表 [dbo].[WeibullSummaryDetails] 时遇到此错误。
这是我的两张桌子
CREATE TABLE [dbo].[WeibullFilterDetails]
(
[WeibullFilterDetailsId] [int] IDENTITY(1,1) NOT NULL,
[ProjectTeamId] int not null,
[WeekStartDate] date not NULL,
[WeekEndDate] date not null ,
[IsRefreshed] bit NULL,
CONSTRAINT FK_WeibullFilterDetails_WeibullFilterDetails
FOREIGN KEY ([ProjectTeamId])
REFERENCES [dbo].[ProjectTeams]([Id]),
PRIMARY KEY ([ProjectTeamId], [WeibullFilterDetailsId])
)
CREATE TABLE [dbo].[WeibullSummaryDetails]
(
[WeibullSummaryDetailsId] [int] IDENTITY(1,1) NOT NULL,
[WeibullFilterDetailsId] int not null,
[ProjectTeamId] int not null,
[ActualEstimatedBugCount] int NULL,
[CurrentBugCount] int NULL,
[PercentageBugFound] float NULL,
[PercentageBugResolved] float NULL,
[BugsToFind] int NULL,
BugsToResolve int NULL,
LinearEquation nvarchar(100) null,
RSquare float NULL,
Shape float NULL,
Scale float NULL
PRIMARY KEY ([WeibullSummaryDetailsId], [WeibullFilterDetailsId],[ProjectTeamId]),
CONSTRAINT FK_WeibullSummaryDetails_WeibullFilterDetails
FOREIGN KEY ([WeibullFilterDetailsId],[ProjectTeamId])
REFERENCES [dbo].[WeibullFilterDetails]([WeibullFilterDetailsId],[ProjectTeamId])
)
详细的错误信息
消息 1776,第 16 级,状态 0,第 14 行
引用表 'dbo.WeibullFilterDetails' 中没有与外键 'FK_WeibullSummaryDetails_WeibullFilterDetails' 中的引用列列表匹配的主键或候选键。消息 1750,第 16 级,状态 0,第 14 行
无法创建约束。查看以前的错误。
我看过其他关于这个错误的帖子,通常给出的解决方案是如果父表有一个复合键,那么这两个列也应该存在于子表中,并且应该用于外键约束。
这正是我在这里所做的,但仍然出现此错误。
非常感谢您的帮助!
【问题讨论】:
标签: sql foreign-keys composite-key