简体   繁体   中英

What would be the correct way to organize this MySQL database?

I am creating a site similar to reddit where users can vote on links. Here are my 3 MySQL tables so far:

users

id | username | email | password

urls

id | url | description | submittedBy (references users.username) | upvotes | downvotes

comments

urlid (references url.id) | submittedBy (references users.username) | description

My question is; How would I document who upvotes and downvotes each url. I don't know if I need to

  • Make a new table for each url and have each row have a user and whether they upvoted or downvoted
  • Somehow store a list of what each specific user has voted on in the 'users' table
  • Store a list in the 'url' table of all users who have upvoted/downvoted that url

You need another table that stores the user id, the url id and the vote. I would use a simple u|d for up or down but you could use 0|1 or anything that you like.

votes
url_id | user_id | vote

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM