好友动态数据库设计思路

On 08/26/2010, in mysql, by kilobug

table: behavior 行为表
table: friend_behavior 好友行为关系表

table [behavior] field:
bid[int 10]:行为ID
uid[int 10]: 用户ID
event[varchar 20]:事件(如添加好友则用friend_add表示
behavior[text]: 行为内容(json序列化数组后的字符串)
flagid: 标识ID,用于删除动态
lastime[int 10]: 最后时间
table [behavior] index:
bid: 主键
uid, event, flag: 联合唯一索引

table [friend_behavior] field:
uid: 用户ID
fuid: 好友ID
bid: 行为ID
lastime: 最后时间
table [friend_behavior] index:
uid, fuid: 联合普通索引
bid: 普通索引

实例:
1、查询指定用户最新的好友动态:

SELECT fb.fuid, b.event, b.behavior, b.lastime FROM `friend_behavior` fb LEFT JOIN `behavior` b ON(b.`uid`=fb.`fuid`) WHERE fb.`uid`=xxx ORDER BY b.`lastime` DESC

2、查询指定用户最新的动态

SELECT uid, event, behavior, lastime FROM `behavior` WHERE `uid`=xxx ORDER BY `lastime` DESC

……

Tagged with:  

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

无觅相关文章插件,快速提升流量