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 trial
Mauro Bonucci
5,953 Pointsrelational tables
Hi there, in the past months i been working whit php and mysql, and normally when i create my database i use a lot the concept of relational tables, for example i have a list of movies in a table, and than i have another table of genre. In the table movies i have a column called genre_id like in the courses we learn. Bascally my question is, what is the difference in assigning a column has a foreign key whit one that isnt assign, cant i have the same result? Many times i worked whit joins or where clause and i never notice the difference when i dont assign a column has a foreign key.
Sorry if the question looks dumb, but hope to find the difference.
1 Answer
Iago Wandalsen Prates
21,699 PointsWhat a foreign key does is, when you put a new row on the table, its going to check if the corresponding key exists on the other table, if it doesn't, its going to fail the insert. Its basically an extra validation, SQL native.
So yes, you can have the same result with either one.
Mauro Bonucci
5,953 PointsMauro Bonucci
5,953 PointsYes, it makes real sense, this is exactelly the ideia i had, i was just not sure