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.
19
Upvotes
View all comments
Show parent comment
1
u/Far_Swordfish5729 Dec 10 '25
The distinction is that I can join on and index a foreign key column that does not actually have the constraint on it. However that can allow bad data and will make the schema harder to read. But you are free to join however you want.