我正在尝试查找这样的查询。在mysql中可以吗?
ALTER TABLE `table1`
ADD CONSTRAINT my_constraint_name
FOREIGN KEY (some_id, some_other_id) REFERENCES `table2`(id, other_id);
我的情况是,table1.some_id
应该引用table2.id
,它也应该满足table1.some_other_id
来自同一个table2 的行,即 table2.other_id
最佳答案
Yes, this is possible in MySQL.
这应该工作得很好。
ALTER TABLE table1
ADD CONSTRAINT table1_fk FOREIGN KEY (`column1`, `column2`)
REFERENCES table2 (column1, column2);
关于mysql - 有没有办法为 mysql 列添加多个外键,但它们应该引用其他表中的行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36861124/