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/Posaquatl Apr 10 '21
Yeah I suppose you are right. Was trying to sort out how to constraint on album names since there would be dups of those. Everyone has a Live album lol. I was using ON CONFLICT in a lot of my inserts. I suspect I might need to change it into doing look ups first or performing a wider combination of constraints to other columns. My first major DB project like this so has been a learning experience.