如何在MySQL标签中存储标签,一个字段总共或一个为每个标签提交? [英] How to store tags in MySQL tags, one field in total or one filed for each tag?
问题描述
我认为多对多关系将有助于您p>
像
-------- --- -------------- ------------
- 标签 - < -------> - products_tags - < -------> - 产品 -
-------- ----------------- ------------
编辑:
多对多的方法是更规范化但是我认为最难实现,因为在这种情况下,为了获得给定的产品的所有标签。
优点:
- 完全正常化
- DRY :由于
如果您需要更改标签名称,您
可以做到,您将看到
无处不在 - 等。
另一种方法是保存所有标签在一个字段中分开的东西(让我们说逗号)。在这里,您可以获得标签的速度。你只需要用分隔符拆分标签就可以了。保存标签更容易。
但是我不喜欢这种方法,因为如果你需要更新一个模板,你需要按文章,拆分,更新,然后保存。
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?
I think the Many to Many relationship will help you
something like
-------- ----------------- ------------
- tags - <-------> - products_tags - <-------> - products -
-------- ----------------- ------------
edit:
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:
- totally normalized
- DRY: since if you need to change a tag name you can do it and you will see the change everywhere
- etc.
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..
这篇关于如何在MySQL标签中存储标签,一个字段总共或一个为每个标签提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!