我创建了一些看起来像这样的表
CREATE TABLE sickness
(
sickness_id number(2),
sickness_name varchar2(20),
PRIMARY KEY (sickness_id)
);
CREATE TABLE cover
(
cover_needed char(1) NOT NULL,
employee_id number(3),
responsibilities varchar2(50),
notes varchar2(50),
PRIMARY KEY (cover_needed, employee_id)
);
这很好用然后当我尝试制作一个父表(见下文)时,我得到了错误。
ORA-02270: no matching unique or primary key for this column-list
然而,我把它缩小到最后一行,但我不能为我的生活弄清楚,谢谢
CREATE TABLE absences
(
absences_id number(2) NOT NULL,
manager_id number(3),
employee_id number(3) NOT NULL,
absence_name varchar2(15) NOT NULL,
sickness_id number(2),
date_from date NOT NULL,
date_to date NOT NULL,
length number(2) NOT NULL,
description varchar2(40),
authorised_by_manager char(1) NOT NULL,
cover_needed char(1) NOT NULL,
half_day char(1) NOT NULL,
PRIMARY KEY (absences_id, manager_id, employee_id),
FOREIGN KEY (sickness_id) REFERENCES sickness (sickness_id),
FOREIGN KEY (cover_needed) REFERENCES cover (cover_needed)
);
答案 0 :(得分:0)
这是您定义cover
:
CREATE TABLE cover (
. . .
**PRIMARY KEY (cover_needed, employee_id)**
);
您有一个复合主键。外键引用需要引用两个键。 。 。并以相同的顺序。
所以:
FOREIGN KEY (cover_needed, employee_id)
REFERENCES cover (cover_needed, employee_id)
如果您使用自动生成的数字主键,我认为您的数据结构和查询会更简单。这将简化外键关系并简化连接表的查询。