我想创建一个由int列和datetime列组成的外键约束(两者都不为空)。SQL Server外键问题
我收到错误 “引用表X中没有与外键FK中的引用列表匹配的主键或候选键”。
通常,此错误表示目标表中的列不是唯一的。 但它是主键,所以它绝对是独一无二的。
外键正在引用的表跨多个文件组进行分区 - 而在其上创建外键的表驻留在主文件组上。这可能是问题吗? 日期时间可以成为外键的一部分吗?
表X:
LineId (int not null) (PK)
CreatedAt (datetime not null) (PK)
Message (nvarchar(max))
userId (int not null)
表Y:
LineId (int not null) (PK) (FK)
SId (int not null) (PK)
LineCreatedAt (datetime not null) (FK)
CreatedAt (datetime not null)
SQL命令:
ALTER TABLE Y
ADD CONSTRAINT [FK1]
FOREIGN KEY(LineId,LineCreatedAt)
REFERENCES X(LineId, CreatedAt)
理解任何想法。
谢谢
是否有可能向我们展示您的表格架构? – Graviton 2009-12-16 11:11:13
我想知道是否因为表X的索引在分区方案上,而表Y不是? – Chris 2009-12-16 12:23:24