Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Database question

Posted on 2011-03-07
3
Medium Priority
?
331 Views
Last Modified: 2012-12-13
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.
0
Comment
Question by:flynny
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
raulggonzalez earned 2000 total points
ID: 35055304
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
 

Author Comment

by:flynny
ID: 35056458
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
 
LVL 8

Expert Comment

by:raulggonzalez
ID: 35056984
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

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Your data is at risk. Probably more today that at any other time in history. There are simply more people with more access to the Web with bad intentions.
Recursive SQL is one of the most fascinating and powerful and yet dangerous feature offered in many modern databases today using a Common Table Expression (CTE) first introduced in the ANSI SQL 99 standard. The first implementations of CTE began ap…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Suggested Courses

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question