gpt4 book ai didi

mysql - 为消息应用程序创建数据库

转载 作者:行者123 更新时间:2023-11-29 12:25:11 25 4
gpt4 key购买 nike

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

最佳答案

基本上,创建一个包含字段 user_idfrienduser_id 的表 users_rel (或其他内容),并相应地添加好友。

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

使用 user_id、frienduser_id 作为键以避免重复条目。

关于mysql - 为消息应用程序创建数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28434497/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com