oracle引用列的数量必须与引用的列匹配

时间:2012-09-10 20:26:11

标签: sql

我不断收到错误说明外键引用列表中的列数不等于引用列表中的列数。

这是我收到错误的行。

      foreign key(EID, Lastname, Firstname, Midinitial) references employee,

有谁知道我收到此错误的原因?

create table employee(
  EID varchar(20) primary key,
  Lastname varchar(20),
  Firstname varchar(20),
  Midinitial char(1),
  gender char(1),
  street varchar(20),
  city varchar(20)
);

create table works(
  EID varchar(20) primary key,
  Lastname varchar(20),
  Firstname varchar(20),
  Midinitial char(1),
  company_name varchar(20),
  salary numeric(5,0),
  foreign key(EID, Lastname, Firstname, Midinitial) references employee,
  foreign key(company_name) references company
);

create table company(
  company_name varchar(20) primary key,
  city varchar(20),
  foreign key(city)references employee
);

1 个答案:

答案 0 :(得分:1)

您只需要来自员工的主键:

foreign key(EID) references employee