SQL - Best practice for a Friendship table

后端 未结 5 1421
青春惊慌失措
青春惊慌失措 2020-12-14 03:58

Before you show me duplicates, please note that I\'ve searched through the site an have found some examples but not quite specific to my prob

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-14 04:20

    Table User: UserId
    Table Friendship: FriendshipId
    Table UserFriendships: UserId, FriendshipId, FriendshipStatus
    

    You can add a UNIQUE constraint to prevent a User from being in a Friendship twice.


    You have Users and Friendships. Users can join Friendships (which can be 0 or more Users) by creating a record in the third table.

提交回复
热议问题