我尝试执行以下代码
CREATE TABLE ShoppingCentreShop (
CentreCode varchar(255),
ShopNo int,
Category varchar(255),
CustomerRating int,
**CONSTRAINT CHK_Category CHECK ( Category in ('FASHION', 'ENTERTAINMENT','FOOD')),**
CONSTRAINT CHK_CustomerRating CHECK ( CustomerRating between 1 and 5),
CONSTRAINT fk_ShoppingCentre_CentreCode FOREIGN KEY (CentreCode) REFERENCES ShoppingCentre(CentreCode),
CONSTRAINT fk_Shop_ShopNo FOREIGN KEY (ShopNo) REFERENCES Shop(ShopNo)
);
我得到以下错误代码
错误出现在粗体代码行上 ” 我是MySQL的初学者,因此非常感谢您
编辑:我也得到以下错误行
“#1005-无法创建表shopping_centres
。shoppingcentreshop
(错误号:150“外键约束格式不正确”)(详细信息...)”
答案 0 :(得分:0)
为什么不使用ENUM()?
CREATE TABLE ShoppingCentreShop
(
CentreCode varchar(255),
ShopNo int,
Category ENUM('FASHION','ENTERTAINMENT','FOOD'),
CustomerRating int,
CONSTRAINT CHK_CustomerRating CHECK (CustomerRating BETWEEN 1 AND 5),
CONSTRAINT fk_ShoppingCentre_CentreCode FOREIGN KEY (CentreCode) REFERENCES ShoppingCentre(CentreCode),
CONSTRAINT fk_Shop_ShopNo FOREIGN KEY (ShopNo) REFERENCES Shop(ShopNo)
)