Several values ​​in a column

I need some advice regarding multiple entries. I have a table with fields username, messageand message_to. A script can send one message to multiple users at a time. What do you suggest? Would it be efficient to keep all recipients in a single column with commas or add multiple records?

+3
source share
1 answer

No no no no no.

This would be a serious violation of the relational database model. Create three tables: users, messages, and sentToUsers messages.

  • In the table, Userssave the value user_idand the user name.
  • Messages message_id text.
  • MessagesSentToUsers , . user_id , , message_id, , .

:

|       User     |  |      Message      |  |  MessageSentToUsers   |
|---------|------|  |------------|------|  |----------|------------|
| user_id | name |  | message_id | text |  | user_id  | message_id |

id integer. , ( ).

+10

Source: https://habr.com/ru/post/1738830/


All Articles