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

General Discussion

Thomas Joseph Meneses
Thomas Joseph Meneses
9,838 Points

Do foreign keys affect SQL JOIN operations?

Learning about normalization and joining tables, as well as about foreign keys, really piqued my programmer's curiosity. Both concepts seem to go hand-in-hand, particularly that both mean to define and then use table relationships. And yet wherever I looked, no one seemed to be asking this question (not even in the almighty Stack Overflow).

Can the constraint of having foreign keys allow in some way the SQL engine to JOIN the respective parent and child tables in a way that's somehow better than not having foreign keys defined at all? Although the constraints are defined, it seems as though a JOIN still requires the coder to set the related columns through ON [table1].[col1] = [table2].[col2].

If there is now way to depend on the previously defined foreign key when doing a JOIN, then it is in my opinion a violation of DRY since you already defined the relationship, and yet need to define it again when JOINing the related tables.