r/DatabaseHelp • u/Posaquatl • Apr 10 '21
Postgres Primary Key Question
Quick question on table design in Postgres as I wrap my head around primary and foreign keys. I can creating a DB to store all my media file information. Which includes pulling details such as Artist and Album of the file metadata. When creating the tables such as Artist, I have an artist_id as a auto incrementing serial. artist_name would be the primary key in order to keep things unique. Would the artist_id be considered a primary key as well?? Since it would be referenced by other tables as a foreign key. Still learning this but I think that is the correct idea. The name is not stored in the other tables just the id. And documentation mentions that foreign keys point to the primary key.
Example of my layout so far. https://imgur.com/a/XmjxxiE
View all comments
Show parent comment
1
u/BrainJar Apr 10 '21
Candidate keys are the columns that could potentially be the primary key. There may be more than one in any table. Regarding artist names, there are plenty of bands or individual artists with the same name. Maybe not in your collection, but it’s definitely a real world scenario. A quick search on Google will show you plenty.