Jump to content

Need help with database structure


siublue
Go to solution Solved by siublue,

Recommended Posts

Hi. I am creating a database where a user can store up to 50 names of their family members. I have two table structures in mind and curious which one is the more efficient structure.


====================================================================================================

TABLE A:
userid-firstfamilymemberid-firstfamilymembername-secondfamilymemberid-secondfamilymembername   

 

 

Note:(the columns would repeated until the fiftiethfamilymemberid and fiftiethfamilymembername for a total of 101 columns)

 

 

TABLE B:
userid-familymemberid-familymembername

======================================================================================================
which is more efficient... Table A which would have more columns but less rows or Table B which would have less rows but more columns.. also keep in mind that the fixed amount is 50 family members per a user. Thanks in advance.





 

Link to comment
Share on other sites

You would have one table for the users and a separate table for their family members. The family member table would look something like Table B. But, it is customary to have the first field to be the primary ID of the table. So, it would look mire like this:

 

Table: family_members

family_member_id (primary key)

user_id (foreign key)

name

. . . additional fields to describe the family member

 

 

THe above assumes that a family member would belong to one, and only one, user. If a family member can be associated with multiple users, then you would not include the user_if in that table. Instead, you would use a third table to maintain the associations. Each record would contain foreign keys for the users and the family members.

Link to comment
Share on other sites

I would have two tables

+------------+
|   user     |
+------------+              +------------+
| userid     |-----+        |  family    |
| name       |     |        +------------+
+------------+     |        | id         |
                   |        | membername |
                   +-------<| userid     | 
                            +------------+

then any user can have as few or many family members as they need. No arbitrary limits because you allowed 50 columns.

 

(Sorry, Psycho. I refreshed before typing and you weren't there)

Edited by Barand
Link to comment
Share on other sites

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.