gpt4 book ai didi

Mysql 用一个引用多个列

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

如何使 3 列具有字段引用?下面的代码不正确。

CREATE TABLE `example` (

`id` bigint(20) NOT NULL AUTO_INCREMENT,
`userid_do1` int(11) DEFAULT NULL,
`userid_do2` int(11) DEFAULT NULL,
`userid_do3` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
CONSTRAINT `example_ibfk_1` FOREIGN KEY (`userid_do1,userid_do2,userid_do3`) REFERENCES `usertable` (`id`),
) ENGINE=InnoDB

最佳答案

您需要为引用另一表列的每一列创建一个约束。

CONSTRAINT example_ibfk_1 FOREIGN KEY (userid_do1) REFERENCES usertable(id),
CONSTRAINT example_ibfk_2 FOREIGN KEY (userid_do2) REFERENCES usertable(id),
CONSTRAINT example_ibfk_3 FOREIGN KEY (userid_do3) REFERENCES usertable(id)

关于Mysql 用一个引用多个列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18522863/

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