当我尝试在同一个表中创建两个外键时遇到此问题 我如何解决它&谢谢
create table employee(
employeeNumber INT (11) primary key,
);
create table projects(
projectNumber INT(11) primary key ,
);
create table workat(
wemployeeNumber INT(11),
wprojectNUmber INT (11),
primary key (wemployeeNumber,wprojectNUmber),
FOREIGN key workat(wemployeeNumber) references employee(employeeNumber),
FOREIGN key workat(wprojectNUmber) references projects(projectNumber)
);
答案 0 :(得分:1)
您的FOREIGN KEY
语法对我而言,我不知道您为什么要在workat
中包含该定义。试试这个版本:
CREATE TABLE workat (
wemployeeNumber INT(11),
wprojectNUmber INT(11),
PRIMARY KEY (wemployeeNumber, wprojectNumber),
FOREIGN KEY (wemployeeNumber) REFERENCES employee (employeeNumber),
-- projects, not project
FOREIGN KEY (wprojectNUmber) REFERENCES projects (projectNumber)
);
这是一个演示,显示您的代码在进行上述更改后进行编译: