Reputation: 25314
I am developing a product which is close to stackoverflow.com. A poster is required to enter tags for his problem or task. How to store these tags in the database, one field(column) in total or one field(column) for one tag?
Upvotes: 2
Views: 6218
Reputation: 7956
I think the Many to Many relationship will help you
something like
-------- ----------------- ------------
- tags - <-------> - products_tags - <-------> - products -
-------- ----------------- ------------
the Many to Many approach is the more normalized one, but I think the hardest to implement, since is based in joins to get all tags for a given "product" in this case. advantages:
the other approach is to save all tags in one field separated by something (let say comma). Here you have speed in terms of getting the tags. you just need split the tags by that separator and thats it. Saving tags is more easy too. but I dont like this approach because if you need to update a template you need to go article by article, split, update, and then save..
Upvotes: 8
Reputation: 3880
I would do something like this...
tblAvailableTags
- tag_id
- tag_name
tblTasks
- task_id
- task_name
- ...etc
tblTaskTags
- task_tag_id
- task_id
- tag_id
So tblTaskTags would be your link between the two...so you could do something to the effect of
SELECT * FROM tblTaskTags WHERE task_id = selected task id
Upvotes: 2