7
sql 表设计问题:需索引的可选字段应该允许 null 吗?
source link: https://www.v2ex.com/t/905289
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
比如一个用户表,中间一个字段,表示用户所属的企业。
用户可能不属于任何企业。
那么有两种解决方案:
- 企业字段允许为 null 。用户不属于企业时,企业字段为 null 。
- 企业字段不允许为 null ,默认 0 。用户不属于企业时,企业字段为 0 。
再叠加一个需求,用户表的企业字段需要加索引。
那么,应该选择哪个方案?或者有没有更好的方案?
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK