简体   繁体   English

对数据库中的每个“会话”使用新的SQL表

[英]Use new SQL table for each “conversation” in db

I have this web application I'm developing for my major project, one of it features is messaging between registered users. 我有一个正在为我的主要项目开发的Web应用程序,其功能之一是注册用户之间的消息传递。 The whole messaging system is created that every time when message is sent, new record in table conversations is created and new table in second database is created, table name is made from id of both users and conversation id. 创建整个消息传递系统,每次发送消息时,都会在表对话中创建新记录,并在第二个数据库中创建新表,并根据用户ID和对话ID来创建表名。 In this table whole conversation between two ppl is stored. 在此表中,存储了两个ppl之间的整个对话。

My question is, is this good approach or creating tables at my database on daily basis would be to much for server to handle? 我的问题是,这种好方法还是每天在我的数据库上创建表对服务器来说足够多了?

Creating new tables based on request is never a good idea. 根据请求创建新表绝不是一个好主意。 You could create a table which connects user_ids to a conversation: 您可以创建一个表,用于将user_ids连接到对话:

conversations:
id : 2348
started_at: 2013-03-28 17:13:00

user_conversations:
id        : 538
conversation_id: 2348
message   : "Hey Jakub, how are you?"
user_id   : 5831
posted_at : 2013-03-28 17:14:50

id        : 539
conversation_id: 2348
message   : "Hey Anyone, I'm fine, how are you?"
user_id   : 95234
posted_at : 2013-03-28 17:15:30

etc. 等等

id: PK, key on user_id id:PK,user_id上的密钥

You might want to play around with keys tho, but this is a nice setup for this. 您可能想使用tho键,但这是一个不错的设置。 You will connect messages to a user and a coversation. 您将把消息连接到用户和掩护。 This way a conversation is not limited to 2 users either. 这样,会话也不限于2个用户。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM