Reputation: 1862
I'm looking to set up a blog database on my website. I'm setting up a MySQL database with a posts table with the attributes: post_id, datetime, content (all pretty self-explanatory). I want each post to have tags (which can be any number of tags). Obviously, this needs a table on its own, so I made a tags table with attributes: tag_id, tag_name. Now, to link them I guess I should make a third table, called post_tag which will define links between posts and tags, so it will have attributes: post_id, tag_id. I'm sort of new to database structuring, so I'm wondering if I'm doing this the right way, or if there is perhaps a more efficient way at tackling this problem?
Any help is appreciated.
Upvotes: 0
Views: 83
Reputation: 2597
If posts can have multiple tags you should have 3 tables:
posts: post_id,postname ........
tags: tag_id,tag_name
post-tags (linked table) post_id,tag_id
This may be interested for you: http://databases.about.com/od/specificproducts/a/normalization.htm
Upvotes: 1