如何创建“我的朋友活动”表以获得更好的阅读效果

时间:2012-02-26 20:04:16

标签: database database-design relational-database

在一个社交网站中,我想在sql server db中创建一个表来保存所有朋友的活动,这些活动会在页面中加载看起来像facebook“News Feed”,这些活动的例子如下:

  • 朋友添加了一张照片
  • 一位朋友改变了他的个人资料照片
  • 朋友喜欢照片
  • 一位朋友评论了一张照片

所以我创建了下表:

Id  uniqueidentifier
UserId  uniqueidentifier -> The friend how did the activity
ObjectId    uniqueidentifier -> entity id which the user did the activity on such as photo id.
Type    int -> Type of the activity
CreatedOn   datetime 
Data    nvarchar(MAX) -> extra data about the object the user did the activity on.

但是现在从这个表中选择我应该得到所有朋友ID然后使用这些id从这个活动表中选择或者进行连接。

我希望只是从这张表中获取所有内容而无需访问朋友表,这是可能的,我应该添加哪些列以使阅读更容易?

1 个答案:

答案 0 :(得分:0)

是的,您需要为特定用户选择所有朋友,然后加入此表以获取活动。我还建议在userid上添加一个索引,在列上创建,这将加快处理速度