Mysql将列与一个引用相乘

时间:2013-08-30 00:03:36

标签: mysql foreign-keys

如何使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

1 个答案:

答案 0 :(得分:2)

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

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)