且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

你应该把自引用表列作为外键吗?

更新时间:2023-02-02 23:15:56

是的。确保您没有孤儿(没有父项的条目),根据用法,如果您定义级联删除,则删除父项时,其所有子项也将被删除。

Yes. Ensures that you don't have an orphan (entry with no parent), and depending on usage, if you define a cascading delete, when a parent is deleted, all its children will also be deleted.

缺点是像任何其他外键一样轻微的性能损失。

Disadvantage would be a slight performance hit just like any other foreign key.