数据库设计 - 可选字段
我将添加一个为用户提供可选标题的字段。创建一个包含 1 个或多个带有 id 字段的额外表来用作查找是一种好的做法吗?这被认为是有效的吗?还有其他解决方案吗?
I'm about to add a field which gives users an optional title. Is it good practise to create an extra table with 1 or more fields with an id to serve as a lookup? Is this considered efficient and are there other solutions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果你要为人们提供一个标题列表中的选择,并打算在这个领域进行分析,那么将其标准化是值得的。否则,空间上的微小节省不可能抵消所带来的不便。
空字段不会占用数据库中的任何空间,除非它们是固定宽度的(甚至可能不占用,具体取决于 DMBS)。这样做的好处不是避免空字段,而是避免重复或脏数据,这使得正确的分析变得不可能。
If you are going to offer people a choice from a list of titles, and intend to do analysis on this field, then it would be worthwhile to normalize it. Otherwise, the minor savings in space would be unlikely to outweigh the inconvenience.
Empty fields don't take up any space in a database unless they are fixed width (and maybe not even then, depending on the DMBS). The benefit is not in avoiding empty fields, it would be in avoiding repeated or dirty data, which makes decent analysis impossible.
为了搜索目的,最好有额外的表格,但对于可选标题,您可以在同一个表格中创建另一个字段。
For Searching purpose it is best to have extra table, but for only optional title you can create another field in same table.