Advice on design relations between tables

后端 未结 2 1914
-上瘾入骨i
-上瘾入骨i 2021-01-15 18:01

I have information about music albums that I want to organise in RDBMS tables with relations between them. I have the following info for each album: artist, album name, year

2条回答
  •  无人共我
    2021-01-15 18:49

    The bottom line is that you need foreign keys. Your tables currently have a distinct id for each table named id:

    artist.id
    artist.name
    album.id
    album.album
    album.year
    album.label
    album.rating
    genre.id
    genre.name
    genre.id
    genre.name
    

    Key word is "relational" here. You need to relate the tables. Perhaps you'd design this by naming your ids better:

    artist.artist_id
    album.album_id
    genre.genre_id
    

    Then in the album table, you will add columns for artist_id and genre_id so you can join them back to the artist and genre tables

    Without FKs, you will have a Cartesian product. Simple as that.

提交回复
热议问题