I'm looking for some advice on how to design a database for an email-style application, specifically how to handle sending a message to multiple users, and displaying what messages were sent to what users.
This is what I have so far:
Messages (Primary Key is Id)
- Id (Identity)
- SenderId (Foreign Key to Users.Id)
- <message data>
ReceivedMessages (Primary key is MessageId + RecipientId)
- MessageId (Foreign Key to Messages.Id)
- RecipientId (Foreign Key to Users.Id)
- IsRead
So for every message sent, there would be one row in Messages, with the data, and then one row for each recipient in ReceivedMessages.
But what if I want to view all the messages sent by a user, and who they were sent to? For each message, I'd need to find all the ReceivedMessages rows for that message, and join all of those with the user table, and then somehow concat all the names (something like this: Concatenate many rows into a single text string?). Might this cause scaling issues, or is it not really anything to worry about?
Any thoughts/suggestions? Thanks.