我正在尝试创建三个表,但是出现错误
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'REFERENCES personal_details(personID)
)'
上述错误适用于第三张表,即表hobbies_person
。
我正在创建如下表。
CREATE TABLE personal_details (
personID INT PRIMARY KEY,
firstName varchar(30),
middleName varchar(30),
lastName varchar(30),
age INT,
aboutMe varchar(500)
);
CREATE TABLE hobbies (
hobbID INT PRIMARY KEY,
hobbName varchar(30)
);
CREATE TABLE hobbies_person (
personID INT,
hobbID INT,
PRIMARY KEY (personID, hobbID),
FOREIGN KEY personID REFERENCES personal_details(personID)
);
我也试过
CREATE TABLE hobbies_person (
personID INT,
hobbID INT,
PRIMARY KEY (personID, hobbID),
FOREIGN KEY personID REFERENCES personal_details(personID),
FOREIGN KEY hobbID REFERENCES hobbies(hobbID)
);
但仍然是同样的错误。
检查查询的链接
知道如何解决这个问题吗?
笔记
在表中hobbies_person
,我使用复合主键作为PRIMARY KEY (personID, hobbID),