What is the most efficient way to store tags in a database?

后端 未结 7 1172
無奈伤痛
無奈伤痛 2020-11-27 09:06

I am implementing a tagging system on my website similar to one stackoverflow uses, my question is - what is the most effective way to store tags so that they may be searche

相关标签:
7条回答
  • 2020-11-27 09:43

    One item is going to have many tags. And one tag will belong to many items. This implies to me that you'll quite possibly need an intermediary table to overcome the many-to-many obstacle.

    Something like:

    Table: Items
    Columns: Item_ID, Item_Title, Content

    Table: Tags
    Columns: Tag_ID, Tag_Title

    Table: Items_Tags
    Columns: Item_ID, Tag_ID

    It might be that your web app is very very popular and need de-normalizing down the road, but it's pointless muddying the waters too early.

    0 讨论(0)
提交回复
热议问题