我正在尝试创建一系列具有多个外键关系的表。两个表中的第一个有一个两列的主键,一个由我们指定,另一个由制造商指定。尝试第三次查询时发生错误。我不太确定这里出了什么问题,所以任何帮助都将不胜感激。
SQL
CREATE TABLE rugs (
id INTEGER NOT NULL AUTO_INCREMENT,
manufacturer_id INTEGER NOT NULL,
name VARCHAR(255),
description TEXT,
PRIMARY KEY (id, manufacturer_id)
);
CREATE TABLE carpets (
id INTEGER NOT NULL AUTO_INCREMENT,
manufacturer_id INTEGER NOT NULL,
name VARCHAR(255),
warranty TEXT,
description TEXT,
fiber_name VARCHAR(255),
brand_name VARCHAR(255),
texture_name VARCHAR(255),
PRIMARY KEY (id, manufacturer_id)
);
CREATE TABLE carpet_styles (
id INTEGER NOT NULL AUTO_INCREMENT,
carpet_id INTEGER,
style_name VARCHAR(255),
PRIMARY KEY (id),
FOREIGN KEY (carpet_id) REFERENCES carpets (manufacturer_id)
);
CREATE TABLE carpet_colors (
id INTEGER NOT NULL AUTO_INCREMENT,
carpet_id INTEGER,
color_name VARCHAR(255),
color_category VARCHAR(255),
PRIMARY KEY (id),
FOREIGN KEY (carpet_id) REFERENCES carpets (manufacturer_id)
);
CREATE TABLE carpet_custom_names (
id INTEGER NOT NULL AUTO_INCREMENT,
carpet_id INTEGER,
custom_name VARCHAR(255),
PRIMARY KEY (id),
FOREIGN KEY (carpet_id) REFERENCES carpets (manufacturer_id)
);
CREATE TABLE rug_styles (
id INTEGER NOT NULL AUTO_INCREMENT,
rug_id INTEGER,
style_name VARCHAR(255),
PRIMARY KEY (id),
FOREIGN KEY (rug_id) REFERENCES rugs (manufacturer_id)
);
CREATE TABLE rug_colors (
id INTEGER NOT NULL AUTO_INCREMENT,
rug_id INTEGER,
color_name VARCHAR(255),
color_category VARCHAR(255),
PRIMARY KEY (id),
FOREIGN KEY (rug_id) REFERENCES rugs (manufacturer_id)
);
CREATE TABLE rug_shapes (
id INTEGER NOT NULL AUTO_INCREMENT,
rug_id INTEGER,
shape_name VARCHAR(255),
shape_category VARCHAR(255),
PRIMARY KEY (id),
FOREIGN KEY (rug_id) REFERENCES rugs (manufacturer_id)
);
CREATE TABLE catalog_contents (
id INTEGER NOT NULL AUTO_INCREMENT,
catalog_id INTEGER,
carpet_id INTEGER,
rug_id INTEGER,
PRIMARY KEY (id),
FOREIGN KEY (rug_id) REFERENCES rugs (id),
FOREIGN KEY (carpet_id) REFERENCES carpets (id),
FOREIGN KEY (catalog_id) REFERENCES catalogs (id)
);