本文介绍了SQL无法创建表(errno:150)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须使用所有这些复合键创建此表。

I have to create this table with all these composite keys.

潜在客户(custname,carmake,carmodel,caryear,carextcolour,cartrim,optioncode)

prospect(custname, carmake, carmodel, caryear, carextcolour, cartrim, optioncode)

上述所有字段被强调显示它们是主要的。所以7个主要复合键。

All the fields above are underlined to show they are primary. So 7 primary composite keys.

由于某种原因,这不会创建表。

For some reason this does not create the table.

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)
);

我正在使用的代码来创建这个充满复合键的表。

the code i'm using to create this table full of composite keys.

推荐答案

只需在查询之前添加此行;)

Just add this row before your query ;)

SET foreign_key_checks = 0;

这篇关于SQL无法创建表(errno:150)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 04:52