Database question

Hi all,

We have been asked to extend a database we wrote t handle a 'email' style message service (similar to facebook and google). So each user would have their own inbox and sent items listing.

for the message structure I am not so sure how to structure it because one thing they want (similar to facebook or gmail) is that the linked messages look like a conversation? so how will I related these? Also how would I handle sending o multiple recipients?

message
messageID
userID
subject - string
message - text
date - timestamp

messageSentUser
messageID
userID

this is where i'm unsure?

messageLink
messageID
messageID
order - int

any ideas??
thanks in advance.
flynnyAsked:
Who is Participating?
 
raulggonzalezConnect With a Mentor Commented:
HI,

I'd go for a similar but slightly different solution.

Create a table MessagesThreads
ID,

And other messagesInThreads
ID,
ThreadID,
MessageID

for a new message you create a new threadID and for any reply/forward  you use the same threadID like the parent object.

If you use messageId, messageId, whay will happen when you have a really long thread?

In my case, you just need to check the threadId or to group by it to have all the messages which belong to the same conversation...

 Good luck
0
 
flynnyAuthor Commented:
Great solution.

Just to check I've got the jist of everything we'd have something like the following;

Thread,
ID

MessageThread
ID
ThreadID (referring to thread table Id)
MessageID (referring to table below )

Message
ID
UserID (link to user sending email)
Subject
Message
Date

MessageUser
MessageID
UserID (to allow for multiple sent)

Then when a user goes to their inbox we would simply have to search the thread table intersected with the message and user table (to get the relevant threads started by the user)

Is the id field in he messagethread table needed can we simply have a joint key on the thread and messageid? Or am I missing something?
0
 
raulggonzalezCommented:
Well, actually you can 'get rid of' the ID in the table MessageThread and just have a compound PK ThreadID MessageID, but I always like having a unique PK instead of compound one.

You can create UNIQUE constraint over those two columns to guarantee the uniqueness of both values...

There are many ways to go the same place, look for the one you think fits better to your environment, needs ...


Good luck!  
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.