Home  >  Q&A  >  body text

mysql - 设计user表的时候的小问题

背景

现在有一个微信的用户表,表结构大概如下:

`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID',
`uid` int(11) NOT NULL COMMENT '用户UID',
`subscribe` int(11) DEFAULT NULL COMMENT '是否关注 0否/1是',
`openid` varchar(32) DEFAULT NULL COMMENT 'openid',

主要是用来绑定用户用的,也就是uidopenid的关联

其中有个subscribe字段,记录用户是否关注的状态。

疑问

  1. 有这个字段的话假如用户取消关注,那么只是把字段置0就行了
  2. 但是表中的uid可能就会出现重复(因为用户取消了又关注之类的),也就是只能uidsubscribe共同确定关注公众号的用户
  3. 这样的用户表是不是不太合理?因为是相当于用户关联的一个表,里面同时有记录属性的subscribe字段
巴扎黑巴扎黑2743 days ago778

reply all(1)I'll reply

  • 怪我咯

    怪我咯2017-04-17 12:10:41

    This should not be a design problem, but a logic problem. Do the update operation before inserting. If the update is successful, there is no need to insert it

    reply
    0
  • Cancelreply