首页 > 解决方案 > 引用表“Doctors”中没有与 FK 匹配的主键或候选键

问题描述

create table Doctors
(did numeric(3)
,description varchar(20)
,referral varchar(20)
,equipment varchar(10)
, primary key(did));

insert into Doctors values
(101,'physician','fever','medicines'),
(102,'physician','cold','tablet'),
(103,'physician','cough','syrup');

create table HCOReport
(serviceid numeric(3)
,IC numeric(10)
,DC numeric(10)
,referral varchar(20) references Doctors(referral)
,primary key(serviceid)
);

insert into HCOReport values
(201,200,300,'fever'),
(202,300,200,'cold'),
(203,200,283,'cold');

create table Inventory
(itemid numeric(10)
,serviceid numeric(3) references HCOReport(serviceid)
,supplier varchar(20)
,listOfSupplies varchar(30)
);

insert into Inventory values
(101,201,'Blue Ridge','medicines'),
(102,202,'Blue Ridge','stethoscope'),
(103,201,'Blue Ridge','equipment');

create table Patients
(pid numeric(3)
,Isinsurance varchar(3)
,cost numeric(10)
, primary key(pid)
);

insert into Patients values
(501,'yes',1000),
(502,'no',10000),
(504,'no',30000);

我不断得到

引用表 Doctors 中没有与外键“FK__HCOReport__refer__278EDA44”中的引用列列表匹配的主键或候选键。

标签: sql

解决方案


推荐阅读