Click here to Skip to main content
15,891,993 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Programmers,
I have one question regarding database. Actually i want to create like functionality in my project. I am giving you a scenario, according to this you can give me suitable suggestions.
Suppose i have multiple products(not fixed, say 1000) show on my website...users can view these products and can like any product(one user can like many products and users also not fixed)
If i have to check which product is liked by which user and which user liked how many products then how i create my database table?

What i am currently doing is:
Product Table : product_id(primary key), product_name
User Table : user_id(primary key), user_name
Like Table : product_id, user_id

I create this Like Table to store values as any user like any products and then i can easily retrieve which user like which product so i am able to achieve my goal and its work fine for small number of records but problem is as records increases it goes too slow for fetching data. So suggest me a good way to do it that doesn't affect its speed.

Thanks.
Posted

1 solution

Have you already tried using Primary Keys [^]and Indexes[^].

For e.g. you could create a composite key on Likes table using a combination of Product and User Id. Not only it will makes sure that you don't have duplicate values, but will also enable to apply the indexes on this table.

I hope that helps!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900