r/learnSQL • u/dagscriss3 • 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
View all comments
Show parent comment
3
u/tkejser Dec 10 '25
Something will change: the database optimiser will become aware that the foreign key is a true subset of the primary key. And that helps with query planning - which makes complex queries (generally) faster.