Reputation: 6789
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!
Upvotes: 3
Views: 1031
Reputation: 24988
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:
ITEM:
ID
CATEGORYID
...
CATEGORY:
ID
NAME
...
With multiple categories per item:
ITEM:
ID
...
CATEGORY:
ID
NAME
...
ITEMCATEGORY:
ITEMID
CATEGORYID
Upvotes: 3