这似乎是一个相当简单的问题,但我还没有弄清楚为什么会这样。
CREATE TABLE Instrument (
name VARCHAR(50),
manufacturer VARCHAR(50),
CONSTRAINT Instrument_PK PRIMARY KEY (name),
CONSTRAINT Instrument_FK1 FOREIGN KEY (manufacturer) REFERENCES Companies(name)
);
CREATE TABLE Companies (
name VARCHAR(50),
CONSTRAINT Companies_PK PRIMARY KEY (name),
);
返回错误:外键约束形成错误
答案 0 :(得分:0)
首次创建Companies
表,然后Instrument
。你这里也有错误的逗号:CONSTRAINT Companies_PK PRIMARY KEY (name),
。
试试这个:
CREATE TABLE Companies (
name VARCHAR(50),
CONSTRAINT Companies_PK PRIMARY KEY (name)
);
CREATE TABLE Instrument (
name VARCHAR(50),
manufacturer VARCHAR(50),
CONSTRAINT Instrument_PK PRIMARY KEY (name),
CONSTRAINT Instrument_FK1 FOREIGN KEY (manufacturer) REFERENCES Companies(name)
);
答案 1 :(得分:0)
我的问题是两个表都引用了彼此,无论哪个顺序,都会引用一个尚不存在的表。