Jump to content

Recommended Posts

In MySQL: (if that's relevant)

 

I've got my 'users' table.. that looks a little like this :

 

iD, email, password.. blah

 

And I have my messages table (that I haven't created yet):

 

iD, user_sent, user_received, message

 

iD, is obviously the message iD.

user_sent, is the user that sent it's iD

user_recieved, is the user that's receiving it's id

message is the message :P

 

Now this just screams bad structure to me, what's a more logical approach?

 

 

I would create an intermediate table; message_map:

 

Table: users

+----+

| ID |

+----+

 

 

Table: message_map

+-----------+---------------+----+

| User_Sent | User_Recieved | ID |

+-----------+---------------+----+

 

ID -> Primary -> auto_increment

 

 

Table: messages

+---------+--------+----+

| Message | Map_ID | ID |

+---------+--------+----+

 

Map_ID -> ID of record in "message_map"

ID -> Primary -> auto_increment

You have to ask yourself is it really worth it?  your original method of store the user_id to sent/receive is good and there is no real need to add a "look up table" for something like this.  I generally only use lookup tables when i need to link a id to a set of information or a string or if it is impossible to know how any time one id will be linked to another id.  for instance i might have a this setup:

priority
-id
-title
-color
-status_id

task
-id
priority_id
etc...

This is needed so i am not store data more than i need to however this is over kill(along with what hostfreak said):

priority
-id
-title
-color
-status_id

task
-id
priority_id
etc...

task_priority_link
-id
-priority_id
-task_id

This is overkill because my priority can only have 1 priroity id, this is the same with your message can only have one sender so keep that in the message database.  If you are allowing user to message more than 1 user with a single message then yes you will want to create a separate database to track that information.  here is an example on where you would want a lookup table.  Say you have forum system and users/user group.  This is would i would set it up:

user_group
-is
-title
-status_id

user
-id
-first_name

user_group_link
-id
-user_id
-user_group_id

This way you can have people me is mutliple user groups easier.  Hope this helps you.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.