sql – Database for messaging with comments and responses

Question:

This is my first question. and I don't know if I'm doing it the right way. So I apologize in advance if I'm wrong. the doubt I have at the moment is not about code. but on how to organize the database into a messaging system.

To give an example I want the messages to work like FB posts the user creates the public message and other users can interact with this message. The question is, I should create a messages table and organize it for example with a Status column that will define if the text is a post or a reply.

OR should I create a table and name it for example [ID]_respostas where ID would be the id of the main message. It's a simple question. but I would like to know how best to work in this case.

Answer:

I suggest you create a table to store posts and another table to store responses, containing a foreign key relating to the posts table. You can also include another key relating to the answer table itself, if you want to link a new answer to an existing answer.

Scroll to Top