sql – 创建没有主键的外键

为什么必须在一个表的列上有一个主键,另一个表的列具有外键引用.
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'.

解决方法

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

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

相关文章

SELECT a.*,b.dp_name,c.pa_name,fm_name=(CASE WHEN a.fm_n...
if not exists(select name from syscolumns where name=&am...
select a.*,pano=a.pa_no,b.pa_name,f.dp_name,e.fw_state_n...
要在 SQL Server 2019 中设置定时自动重启,可以使用 Window...
您收到的错误消息表明数据库 'EastRiver' 的...
首先我需要查询出需要使用SQL Server Profiler跟踪的数据库标...