I currently am working on developing a blogging website. For this application we’re using MySQL as the database. For this application,I created a blog table which contains the following properties:
I want to add tags to this table. What is the recommended way of adding tags to this table so that in the application I can search for articles/blogs based on tags ?
It is common to use many-to-many relationship for tags. In your case it can be a couple of tables:
- tag_id (foreign key to tags)
- article_id (foreign key to articles)
You can set combination of (tag_id, article_id) as primary key. In this case it will be guaranteed that tag can be mentioned only once for the given article.