外键空 - 性能下降 [英] Foreign key null - performance degradation

查看:204
本文介绍了外键空 - 性能下降的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有表中的文件夹列parent_id引用id如果该文件夹有父,如果没有,那么parent_id为空。这是好的解决方案,或者我需要额外的表格为这个连接或其他解决方案?如果可以的话,这个解决方案会有更大的时间执行吗?

pre $表$文件夹
id int主键,//表中的主键
parent_id int引用id,//同一表中id列的外键
....


解决方案

您可以使用 NULL 外键。没问题。我不会为没有父文件夹(根文件夹)的文件夹添加额外的表。这会让你的设计变得更复杂,没有任何好处。


I have table folder where column parent_id references on id if that folder has parent, if not then parent_id is null. Is that ok solution or I need extra table for this connection or other solution? Can foreign key be null at all, and if can is this solution will has bigger time execution ?

table folder(
   id int primary key,            //primary key in my table
   parent_id int references id,   //foreign key on id column in same table
....
)

解决方案

You can have NULL foreign keys. No problems. I would not put an extra table just for folders without a parent (root folders). It will make your design more complicated with no benefits.

这篇关于外键空 - 性能下降的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆