R
R
Roman Rakzin2017-07-01 11:08:21
SQL
Roman Rakzin, 2017-07-01 11:08:21

How to implement a user message storage structure?

I want to implement user correspondence, but the database structure with fields where UserIdFrom and UserIdTo will be will not work, since I want to make group correspondence in the future.
Then it turns out that you need to create the Id of the message and the Id of the user, who wrote it, and then in another table substitute the Id of the message and the users to whom it is addressed? Or how is it done in social networks?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
F
Fortop, 2017-07-01
@Fortop

There are two options.
* introduce the concept of a group as an independent logical unit
* allow addressing a message to more than one user
In any case, there will be users, messages, recipients.
Three tables. In the simplest case, recipients store user_id and msg_id
With a unique key in two fields at once.
The author of the message is stored together with the message in the same table as user_id

K
k2lhu, 2017-07-01
@k2lhu

I did it on two tables, just add a message for each user, usually id_from, id_to, message are indicated for two, only now you will need to add records for each favorite. However, in this case, new members of the correspondence will not be able to read messages that were sent before they appeared in the chat. In my case, according to the TK, this was not required, so far it works like this.

E
Evgeny Bukharev, 2017-07-01
@evgenybuckharev

Designing a database schema for a messaging system?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question