mysql - 具有多个外键的 SQL 表

标签 mysql sql-server

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

 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/

相关文章:

sql-server - 更新单个表上的两个不同行时发生死锁

sql-server - 我必须在 LINQ 中进行什么样的查询才能获取包含对象列表的自定义列表?

sql - Cassandra/HBase 或只是 MySQL : Potential problems doing the next thing

php mysql : UPDATE will only work WHERE data = integer

mysql - 将一列子查询分配给列

php - 如何计算登录系统的总时间?

php - 将文件插入 SQL 数据库并检索它

mysql - 如何处理触发器中的碰撞问题?

sql - Transact-SQL 中有表文字吗?

sql - 如何删除给出单词以及开始和结束字符的表达式