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

sql – 创建没有主键的外键

发布时间:2020-12-12 08:50:57 所属栏目:MsSql教程 来源:网络整理
导读:为什么必须在一个表的列上有一个主键,另一个表的列具有外键引用. create table D(Did int)create table E(Eid int foreign key references D(Did)) 以上查询给出错误: There are no primary or candidate keys in the referenced table 'D' that matchthe re
为什么必须在一个表的列上有一个主键,另一个表的列具有外键引用.
create table D(Did int)
create table E(Eid int foreign key references D(Did))

以上查询给出错误:

There are no primary or candidate keys in the referenced table 'D' that match
the referencing column list in the foreign key 'FK__E__Eid__79C80F94'.

解决方法

简单.如果父表中有两个值相同,那么您如何知道哪一个将子行相关联?
外键的一面必须是明确的

该要求也是“唯一键”,而不仅仅是一个主键,当然是唯一的

(编辑:李大同)

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

    推荐文章
      热点阅读