加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

sqlserver中 在被引用表 'A' 中没有与外键 'c2&

发布时间:2020-12-12 12:45:30 所属栏目:MsSql教程 来源:网络整理
导读:代码如下: create table ddd ( ?? ?name varchar(10) not null, ?? ?age int not null, ??? constraint cc primary key(name,age) ) create table ccc ( ?? ?gender? varchar(20) not null, ?? ?id varchar(20) not null, ?? ?cname varchar(10) not null,

代码如下:

create table ddd

(
?? ?name varchar(10) not null,
?? ?age int not null,
??? constraint cc primary key(name,age)
)

create table ccc
(
?? ?gender? varchar(20) not null,
?? ?id varchar(20) not null,
?? ?cname varchar(10) not null,
?? ?constraint c2 foreign key (cname) references ddd(name)

)

这样的编写会导致如上提示,

消息 1776,级别 16,状态 0,第 1 行
在被引用表 'ddd' 中没有与外键 'c2' 中的引用列列表匹配的主键或候选键。
消息 1750,级别 16,状态 0,第 1 行
无法创建约束。请参阅前面的错误消息。


修改方案:


create table ddd

(
?? ?name varchar(10) primary key not null,
??? --constraint cc primary key(name,age)
)

修改之后错误消失,原因未知,希望有类似经历的朋友给予解答,谢谢!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读