SQL database structure for custom categories
I am creating an online blog site and for each blog post, I would like the user to be able to create / edit / delete their own category so that they can categorize their post.
What is generally considered good database design for user generated categories?
This is my suggested table design. (Is there a name for this db type?)
USER_TABLE
user_id (pk), user_name
CATEGORY_TABLE
category_id (pk), category_name
USER_CATEGORIES
user_id (fk), category_id (fk)
Thanks for helping. I'm sure there is a message in there somewhere, but I couldn't find it. If this is cheating, please let me know and I will delete this question.
source to share
If what you are trying to do is have "private" categories for each user, then that's okay. If, on the other hand, the categories are supposed to be public (sth like tags on stackoverflow), then you might consider another option - not to keep the user category and lt> relationship, instead add a use_counter field to the category table and use triggers to increment it when category (blog post is categorized) or decrement when "freed" (blog post deleted / its category deleted). When use_counter reaches 0, remove the category.
source to share