在数据库中存储类别
如果某个对象可以是视频、音频
或故事
,那么每个类别最好有一个单独的表,还是可以有一个“类型”包含大量
字段?"audio"
、"video"
和 "story"
条目的
1) 假设每个对象只能是一种类型
2) 假设每个对象可以是多种类型(在这种情况下,最好定义一个 ObjectType 表来存储对象和类型之间的关系,对吗?)
(我是使用关系数据库)
谢谢!
If some object can be a video, audio,
or story
is it better to have a separate table for each category or is it OK to have a "type"
field that contains lots and lots of "audio"
, "video"
and "story"
entries?
1) ASSUME that each object can only be of one type
2) ASSUME that each object can be of multiple types (In this case it seems its best to define an ObjectType table that stores the relations between objects and types right?)
(I am using a relational database)
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
下面建议的架构。通过使用 ID 而不是字符串,您可以减少存储量以及数据库引擎连接时所需的工作量。您还可以更轻松地重命名类别,而不必更新使用类别的无数行,只需更新一个 CATEGORY 行即可。
每个项目只有一个类别:
每个项目有多个类别:
Suggested schemas below. By using IDs rather than strings you lessen the amount of storage, and effort required by the database engine when joining. You also make it much easier to rename a category - rather than having to update umpteen rows where category is used, you update the one CATEGORY row.
With just one category per item:
With multiple categories per item: