Best way to store tags in a database?

前端 未结 2 1929
眼角桃花
眼角桃花 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:32

    You need a mapping table.

    Create a table called entries_tags that contains two columns: entry_id and tag_id, with a multi-key on both entries.

    This is called a many-to-many relationship.

提交回复
热议问题