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!

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!

 

 

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?

 

...

 

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.

 

 

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.