celiker
celiker

Reputation: 885

Database design for storing Facebook likes of a user

I'm getting all the likes of the current user, and storing them to a table (user_id, liked_id). The problem is, when I get all the likes again and if there is a change, I just want to insert the new likes. How can I do this efficiently since many users have lots of likes?

Upvotes: 1

Views: 843

Answers (2)

programmer
programmer

Reputation: 318

Yes you can make composite/ combined primary key or make combined of both field as unique. So, it will not add the data that are already there due to key error.Hence only new data will be inserted.

Upvotes: 0

Anders Abel
Anders Abel

Reputation: 69260

Make the (user_id, liked_id) the clustered, primary key of the table. Use a fill-factor of the index that makes room for new pairs and make sure that your update clauses can make efficient use of the clustered index (i.e. always include the user_id in the where clause).

Upvotes: 1

Related Questions