我正在为一个项目的动物园创建一个数据库,当我尝试使用表“动物”中的主键创建表“生活”时,出现错误
CREATE TABLE Department
(DeptName VARCHAR(35),
DeptBuilding VARCHAR(35),
DeptBudget VARCHAR(9),
PRIMARY KEY(DeptName)
);
CREATE TABLE Animals
(AnimalID CHAR(5),
NameLatin VARCHAR(35),
DeptName VARCHAR(35),
AnimalType VARCHAR(10),
AnimalName VARCHAR(10),
PRIMARY KEY(AnimalID),
FOREIGN KEY(DeptName) REFERENCES Department(DeptName) ON DELETE SET NULL
);
CREATE TABLE Houses
(HouseID CHAR(5),
HouseName VARCHAR(35),
TypeHouse VARCHAR(10),
DeptName VARCHAR(35),
PRIMARY KEY(HouseID),
FOREIGN KEY(DeptName) REFERENCES Department(DeptName) ON DELETE SET NULL
);
CREATE TABLE Lives
(AnimalID CHAR(5),
HouseID CHAR(5),
PRIMARY KEY(AnimalID, HouseID),
FOREIGN KEY(AnimalID) REFERENCES Animals(AnimalID) ON DELETE SET NULL,
FOREIGN KEY(HouseID) REFERENCES Houses(HouseID) ON DELETE SET NULL
);
我希望它创建表,但我得到:“外键约束格式不正确”
答案 0 :(得分:1)