表中列与现有的主键或UNIQUE约束不匹配

农夫山泉有点泥土味 2014-04-03 02:02:46
我的表为:

tabel1 主键 a1

table2 主键 a2

table3 主键 a3



table4 主键 a41+a42+a43;

当我创建a1字段/ a2字段/ a3字段/的外键时为 a41 a42 a43出现

表中列与现有的主键或UNIQUE约束不匹配 提示错误! 请问该怎么解决呢?
...全文
1073 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
Neo_whl 2014-04-03
  • 打赏
  • 举报
回复
--是不是这个意思呢?
create table t1
(a1 int not null primary key)

create table t2
(a2 int not null primary key)

create table t3
(a3 int not null primary key)

create table t4
(a41 int not null references t1(a1),
 a42 int not null references t2(a2),
 a43 int not null references t3(a3),
primary key(a41,a42,a43) )
發糞塗牆 2014-04-03
  • 打赏
  • 举报
回复
CONSTRAINT FK_SpecialOfferProduct_SalesOrderDetail FOREIGN KEY
 (ProductID, SpecialOfferID)
REFERENCES SpecialOfferProduct (ProductID, SpecialOfferID)
参考这个写法,你应该要在表1、2、3中完全写上表4中的3列

34,575

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧