jdlev Posted September 16, 2009 Share Posted September 16, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/174503-mysql-databases-create-relationships-or-not-to-create-relationships/ Share on other sites More sharing options...
Mark1inLA Posted September 16, 2009 Share Posted September 16, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/174503-mysql-databases-create-relationships-or-not-to-create-relationships/#findComment-919735 Share on other sites More sharing options...
jdlev Posted September 17, 2009 Author Share Posted September 17, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/174503-mysql-databases-create-relationships-or-not-to-create-relationships/#findComment-920169 Share on other sites More sharing options...
Mark1inLA Posted September 17, 2009 Share Posted September 17, 2009 ... 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. Quote Link to comment https://forums.phpfreaks.com/topic/174503-mysql-databases-create-relationships-or-not-to-create-relationships/#findComment-920222 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.