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

Databases

Gregory Ledger
Gregory Ledger
6,116 Points

How can a primary key be a foreign key on a one to one relation between two tables?

So you have two tables with identical primary keys. How does the primary key on Table 2 act as a foreign key for Table 1. What do the PK and FK constraints look like?

2 Answers

Steven Parker
Steven Parker
231,007 Points

:point_right: You gave an example of a foreign key in your own previous question.

The foreign key just enforces that any value you enter in the constrained column must already exist in the referenced column of the other table.

Gregory Ledger
Gregory Ledger
6,116 Points

I think what was confusing about the video (One to One Relationships) was around 1:17 when Andrews shows us two tables with only one PK in each. Used to tables where there is a PK AND an FK in one, where the FK relates to the PK (only) in the second table. This shows two tables without FK's, but states that the PK of table two can be used as an FK for table one.