Jump to content

MySQL Databases - Create Relationships or Not To Create Relationships?


jdlev

Recommended Posts

I'm working on creating a profile page for individuals.  The problem is, there is a heck of a lot of columns.  I'll be honest, I don't know a lot (well anything really) about linking tables in a database together, or if I should even bother linking tables in a database together. 

 

To give you a brief example, I have a database, we'll call it "customers", and in this database I have tables: General_Information, Interests, and Pictures. 

 

I want to basically have a page display the current information from each of these tables on a 'profile page', and allow the user to add/edit/delete things from their profile.  Now each of these tables has the exact same column: "CustomerID". 

 

Should I set up a relational table structure where it will automatically update the three tables?  Is there any advantage to a relational database structure? 

 

-or-

 

Should I just create a massive single table in this database that has every field accounted for (about 70-80 total columns)?

 

TIA for any advice!

Link to comment
Share on other sites

I'd use outer joins to connect the 2ndary tables (assuming general_information is primary and interests & pictures are optional).

 

so you can use something like this:

 

SELECT *
FROM customers
LEFT JOIN interests ON customers.id = interests.customer_id
LEFT JOIN pictures ON customers.id = pictures.customer_id

 

Hope this helps!

 

 

Link to comment
Share on other sites

I'd use outer joins to connect the 2ndary tables (assuming general_information is primary and interests & pictures are optional).

 

so you can use something like this:

 

SELECT *
FROM customers
LEFT JOIN interests ON customers.id = interests.customer_id
LEFT JOIN pictures ON customers.id = pictures.customer_id

 

Hope this helps!

 

Can you do that in phpmyadmin?  Also, what purpose does a join serve?  I guess the real question is, do I gain anything by separating the customer aspects into seperate tables, or should I just make one massive table with 80 columns?

Link to comment
Share on other sites

 

...

 

Can you do that in phpmyadmin?  Also, what purpose does a join serve?  I guess the real question is, do I gain anything by separating the customer aspects into seperate tables, or should I just make one massive table with 80 columns?

 

Yes, you can run that in phpmyadmin, but you'll have to construct the sql statement. Regarding your other questions, yes it's very important to understand why separating tables is critical, not only for performance, but diskspace as well.

 

Here's a good article that'll explain how/why. It should also give an example of joins at the end of it.

 

 

 

 

 

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.