Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6768341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:03:49+00:00 2026-05-26T15:03:49+00:00

Could you please describe the best way to create a Facebook like feature table

  • 0

Could you please describe the best way to create a Facebook “like” feature table where I can store the likes of users and how? (columsn, pks, etcs)
Also if it’s possible I’d like to know what’s the best and fastest method to retrieve the data from that table.

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:03:50+00:00Added an answer on May 26, 2026 at 3:03 pm

    Because “likes” can be added/removed, they are related to a specific user, and a user can typically only “like” something once, it makes sense to create a table like this:

    CREATE TABLE Post_Likes
    ( 
        Post_ID int FOREIGN KEY REFERENCES Posts(Post_ID),
        User_ID int FOREIGN KEY REFERENCES Users(User_ID),
        created_date datetime,
        CONSTRAINT PKC__Post_Likes__Post_id__User_id PRIMARY KEY (Post_id, User_id)
    )
    

    There are lots of considerations here. post_id and user_id together make a good natural key but will be prone to fragmentation a bit. Having a separate IDENTITY key would not add much as the important index on post_Id would still get fragmented. It may be worth having another index on User_id so the optimizer can quickly find a users’s like but it wolud be better to tune with some real data and query plans.

    In addition to this table, I would cache the running total of likes in the Posts record so you don’t have to JOIN to the child table and SUM all the likes every time you display something, that can get costly quick. You can maintain that value with a trigger or put the code to maintain that value in your DAL.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Could someone please describe what's the correct way to handle the following situation: wchar_t*
Could someone please advise the current best practice around Date and Calendar types. When
Could anyone please describe how to use NHibernate Query Analyzer? I downloaded it and
Could someone please explain for me what is happening here? i feel like the
I would like to know the best way to determine if the following code
Could someone please describe, what happens beneath the linking stage of lib_xxxx libraries under
Guys, could you please describe TortoiseHg extensions which comes with the installation package? What
Could anyone please give a sample or any link that describes how to spawn
I'm a little lost in general, but if someone could please briefly explain why
Could someone please explain when would I want to use delegation instead of inheritance?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.