为信使应用程序创建数据库

Creating a Database to a messenger application

我需要 MySql 中的数据库,我可以保存用户,这些用户可以有朋友并互相发送消息。我有一个 table 用户,我可以保存用户信息,但我不知道如何保存朋友,例如:用户 1 是用户 4、8、9 的朋友,用户 8 是5、6、10、11 的朋友。我想创建一个 table 朋友并保存所有朋友,但我认为如果我有很多用户,这个 table 会非常大。创建此数据库以保存用户及其朋友以及给朋友的消息的最佳方法是什么?我知道基本的 table 关系。

基本上,创建一个具有字段 user_idfrienduser_id 的 table users_rel(或其他东西)并相应地添加朋友。

user_id | frienduser_id
1       | 4
1       | 8
1       | 9
8       | 5
8       | 6
...

使用 user_id, frienduser_id 作为关键字以避免重复输入。