Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

database-design: table of likes?

Tags:

I wonder,
at many websites there is the option to like/dislike a post.
even here of course, at stackoverflow.

so, technically it's a big likes table?

user_id    post_id 

user_id - who voted
post_id - which post is it

is that all about?
a big likes table?
isn't there something more efficient/sophisticated?

like image 536
socksocket Avatar asked Aug 04 '12 12:08

socksocket


People also ask

What is table design database?

Within a database, related data are grouped into tables, each of which consists of rows (also called tuples) and columns, like a spreadsheet. To convert your lists of data into tables, start by creating a table for each type of entity, such as products, sales, customers, and orders.

What is table design in SQL?

The Table Designer is a visual tool where you design and visualizes database tables. Use the SQL Server Management Studio (SSMS) Table Designer to create, edit, or delete tables, columns, keys, indexes, relationships, and constraints.


2 Answers

At it's most basic level, yes, that's all it is.

But then it starts to expand, trying to answer questions like:

  • How much did the user like this post?
  • When did they like the post?
  • How did they find the post?
  • Did they comment on the post?
  • How does the entire group/community like the post

Then you start to want to answer more in depth questions about friends and the community.

like image 82
Brian Hoover Avatar answered Sep 22 '22 18:09

Brian Hoover


I think I can understand your concern. Having to issue a COUNT() everytime the page needs to be presented.

You certainly have to have this basic table, which will be the basis for a COUNT(), but you don't really need to COUNT() it for every access.

Create a totalling table and update it either when the page receives a like or dislike, using a trigger, or call a stored procedure to update it from time to time.

I would say each method is more indicated for different site personalities, ie, more readings or more writings, but you already know that when it comes to likes or dislikes nothing is previsible.

like image 21
Gustavo Pinsard Avatar answered Sep 21 '22 18:09

Gustavo Pinsard