我必须用所有这些复合键创建这个表。
前景(客户名称、汽车制造商、汽车模型、汽车年、carextcolour、cartrim、选项代码)
上面的所有字段都带有下划线以表明它们是主要的。所以 7 个主复合键。
由于某种原因,这不会创建表。
CREATE TABLE prospect
(Custname VARCHAR(25) NOT NULL,
Carmake VARCHAR(25) NOT NULL,
Carmodel VARCHAR(20) NOT NULL,
Caryear VARCHAR(4) NOT NULL,
Carextcolour VARCHAR(10) NOT NULL,
Cartrim VARCHAR(10) NOT NULL,
Optioncode CHAR(4),
CONSTRAINT pkprospect PRIMARY KEY (Custname, Carmake, Carmodel, Caryear, Carextcolour, Cartrim, Optioncode),
CONSTRAINT fkprospect FOREIGN KEY (Custname) REFERENCES customer(Custname),
CONSTRAINT fk2prospect FOREIGN KEY (Carmake) REFERENCES car(Carmake),
CONSTRAINT fk3prospect FOREIGN KEY (Carmodel) REFERENCES car(Carmodel),
CONSTRAINT fk4prospect FOREIGN KEY (Caryear) REFERENCES car(Caryear),
CONSTRAINT fk5prospect FOREIGN KEY (Carextcolour) REFERENCES car(Carextcolour),
CONSTRAINT fk6prospect FOREIGN KEY (Cartrim) REFERENCES car(Cartrim),
CONSTRAINT fk7prospect FOREIGN KEY (Optioncode) REFERENCES optiontable(Optioncode)
);
我用来创建这个充满复合键的表的代码。