Possible Duplicate:
How do you recommend implementing tags or tagging
I have a website with a database that contains a number of articles. I’d like to implement tags similar to the tags on stackoverflow.
I can think of two basic ways to implement them:
-
Create a separate Tags table with a one-to-many relationship with my Articles table.
-
Add a Tags text field to my Articles table.
The first approach seems the best but would require two additional tables that would grow quite large. It seems like there would also be considerable overhead updating and maintaining that data.
The second approach would be far easier to implement and maintain, and use less resources. But searching would be less efficient. I’d probably use LIKE or maybe even full-text searching.
I’m interested in which approach others think is best. Or perhaps there another approach altogether.
I would personally go with option 1, You mention two additional tables later so I assume you’re thinking of.
This shouldn’t require much more in the way of storage than dumping to a field in Article. Plus it is normalised which will always stand you in good stead for the future and will leave your database far better able to search for articles by tag. As for updating, chances are you’ll only be updating occasionally compared to the number of times you’re reading so the impact should be negligible and I cant think of any maintenance tasks beyond ensuring your indices are up to date which you’re going to have to do on other tables anyway and should be automated.
Fringe benefits mean you can quickly create things like a top tags list or a tag cloud.