r/learnSQL • • Dec 09 '25

Primary and foreign key

Hey guys. Im on my journey on learning sql and im on joins now. Ive created 2 tables and both has primary key. When i ask claude if my code is good, it says that my 2nd table needs a foreign key to connect it to the 1st table, but isnt that what primary key is for? I just need someone to eli5 it to me.

18 Upvotes

19 comments sorted by

View all comments

Show parent comment

3

u/tkejser Dec 10 '25

Postgres has code paths that optimise using key knowledge. But like everything else in postgres: it's primitive and simplistic compared to tricks that "classic" databases can pull off.