开发者

Database design for storing Facebook likes of a user

开发者 https://www.devze.com 2023-03-12 03:28 出处:网络
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 t

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?


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).


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消