Best way to store tags in a database?

前端 未结 2 1906
眼角桃花
眼角桃花 2021-01-12 08:10

I have a database that contains two tables:

  • entries
  • tags

The entries table contains posts that each have one or more tags. The problem

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-12 08:40

    You can also do it the SO-way, where in addition to having a junction/mapping/intersection table, you have a list of tags on the entry that's taggable:

    entries table:
    post_id: 3539744, .... tags: sql, database, database-design, tags, data-modeling
    

    If you can't take the performance hit of using a junction table when pulling the associated tags for an entry. Of course extra care has to be taken here because you are dealing with denormalized data.

提交回复
热议问题