Connecting Tech Pros Worldwide Help | Site Map

User and friends database structure

 
LinkBack Thread Tools Search this Thread
  #1  
Old March 12th, 2008, 08:35 AM
LeXave
Guest
 
Posts: n/a
Default User and friends database structure

Hi all

I've got the following problem in my database structure : I have a
table "User". Each user can have one or more friends which are users
too. And I have no idea about the way I must think my structure. My
first idea was to create a second table "User2" which would be an
exact copy of the table "User", but I can't because of the fact that
an user can have several friends...

The best way would be to store friends in a collection, and store this
collection in a field of the table "User". But I have no idea about
the way to do that (if it's possible).

So, do you have another solution ?

Thanks in advance

  #2  
Old March 12th, 2008, 01:25 PM
Allen Browne
Guest
 
Posts: n/a
Default Re: User and friends database structure

Put all the users (including friends) into one table.

The way to link them depends on the kinds of relationships that exist
between them. If they are directional relationships (User 1 has user 2 as a
friend, but that does not imply that user 2 has user 1 as a friend), the 2nd
table would have these fields:
UserID Number relates to the primary key of tblUser
FriendID Number relates to the primary key of tblUser

The combination of the 2 fields together would be primary key in this 2nd
table.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"LeXave" <frharkonnen@gmail.comwrote in message
news:ed24adb9-cd7e-46d0-8f84-0d8f6a7fa9e4@m34g2000hsc.googlegroups.com...
Quote:
>
I've got the following problem in my database structure : I have a
table "User". Each user can have one or more friends which are users
too. And I have no idea about the way I must think my structure. My
first idea was to create a second table "User2" which would be an
exact copy of the table "User", but I can't because of the fact that
an user can have several friends...
>
The best way would be to store friends in a collection, and store this
collection in a field of the table "User". But I have no idea about
the way to do that (if it's possible).
>
So, do you have another solution ?
>
Thanks in advance
  #3  
Old March 12th, 2008, 01:35 PM
Roger
Guest
 
Posts: n/a
Default Re: User and friends database structure

On Mar 12, 2:27*am, LeXave <frharkon...@gmail.comwrote:
Quote:
Hi all
>
I've got the following problem in my database structure : I have a
table "User". Each user can have one or more friends which are users
too. And I have no idea about the way I must think my structure. My
first idea was to create a second table "User2" which would be an
exact copy of the table "User", but I can't because of the fact that
an user can have several friends...
>
The best way would be to store friends in a collection, and store this
collection in a field of the table "User". But I have no idea about
the way to do that (if it's possible).
>
So, do you have another solution ?
>
Thanks in advance
tblUser
userId (pk)
name
address
etc

tblFriend
userId (fk to tblUser.userId)
friendId (fk to tblUser.userId)
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.