Best way to store tags in a database?

℡╲_俬逩灬. 提交于 2019-12-01 04:21:37

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!