Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialSeth Warner
5,348 PointsHow do you doing multiple tables to a single table, or is there a better way for what I am trying to do?
If I was designing a database for a client such as a club, who has members and each member has their very own member code could I make a table that has a column that holds that code number and attach multiple tables two it, each attached table has a different piece of the members codes information, such as a attached table for the emails, an attached table for the first and last names, an attached table for their phone numbers, addresses, etc. so something like this
Create table members id(Int auto_increment primary key); Then in this table add a _id column for each of the attached tables like so?
name_id email_id phone_id address_id
If so what values would I need to give each of these columns in the main table they are all connecting to, as far as key types, and datatypes go?
Seth
1 Answer
Cena Mayo
55,236 PointsSounds like you're on the edges of the concept of foreign keys. That is, an id that connects two (or more) tables of related info. Generally, though, you use them when a given table row may have multiple entries; for example, a CUSTOMER may have many ORDERS, and the you might want to keep the orders in a separate table for purposes of data integrity and consistency. (You can't delete a customer if they have orders, for example.)
In the case you're talking about, I'm not sure why you would want so many small tables, each containing a single piece of information. It seems like that makes for a very complicated table structure with no real benefit (and which may actually slow down database queries.) I could be totally be misunderstanding what you're trying to accomplish, though.
Best, Cena
Seth Warner
5,348 PointsSeth Warner
5,348 PointsHi Cena,
My apologies for not be as clear as requested, I was curious how to create and use bridges and linkable tables so I can start working with one-many many-one many-many
instead of just one-one
Seth