database design for 'followers' and 'followings'?

后端 未结 4 1619
醉话见心
醉话见心 2020-12-23 00:01

Dear database experts/programmers:

I have a mysql table with users information, such as

id      user_id         name etc.
1       userA            
2         


        
4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-23 00:45

    Yes, your design is the usual way of dealing with many-to-many relationships. Search for "modeling many-to-many database" and you will find lots of resources giving you examples of this.

    Add foreign keys from your relationship table to the users table.

    If your relationship involves additional information, you would put that as column in your connecting table. Maybe, for instance, the date when one user started following another.

    A separate surrogate key in the connecting table, like the ID column you have added, can be useful if you will want to have other tables reference your table.

提交回复
热议问题