gpt4 book ai didi

mysql - 如何向表添加递归外键?

转载 作者:行者123 更新时间:2023-11-29 05:40:36 26 4
gpt4 key购买 nike

我有一个像这样的表:

table: comments, with rows: id, author, content, replyto

我想“replyto”在同一个表中引用“id”,我该怎么做?

非常感谢。

最佳答案

类似于:

ALTER TABLE comments ADD CONSTRAINT `my_recursive_constraint` FOREIGN KEY (`reply_to`) REFERENCES `comments` (`id`) 

关于mysql - 如何向表添加递归外键?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7068463/

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