gpt4 book ai didi

mysql - 具有多个外键的 SQL 表

转载 作者:行者123 更新时间:2023-11-29 22:22:29 25 4
gpt4 key购买 nike

我正在尝试制作一个包含多个键的表格

 CREATE TABLE Wishlist (ID integer NOT NULL,  productname varchar(30) NOT NULL, price integer NOT NULL, email varchar(30) NOT NULL, 
PRIMARY KEY (ID),
FOREIGN KEY (productname) REFERENCES products (productname),
FOREIGN KEY (price) REFERENCES products (price),
FOREIGN KEY (email) REFERENCES products (email)
);

The error "a UNIQUE constraint does not exist on referenced columns repeats code" If i change it to:

CREATE TABLE Wishlist (ID integer UNIQUE NOT NULL,  productname varchar(30) NOT NULL, price integer NOT NULL, email varchar(30) NOT NULL, // rest same as above

The error "a UNIQUE constraints already exists on the set of columns in statement repeats code" if i then remove the primary key, the first error message appears, any suggestions??

最佳答案

外键只能配置在外表中已索引的列上。确保外部表中的列已配置索引。通常,大多数外键配置为表 PK,但非聚集索引也可以工作。

关于mysql - 具有多个外键的 SQL 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30580259/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com