Boy, I'm setting up a website that owns the artist chart and an artist can play more than one musical genre, how would I put the genres that the artist plays in the database?
Boy, I'm setting up a website that owns the artist chart and an artist can play more than one musical genre, how would I put the genres that the artist plays in the database?
Here are the tables that I created to illustrate.
Please disregard the names, as I did a little running.
Here I create my artist table
CREATE TABLE artistaMusica(
id_artista SERIAL,
nome VARCHAR(10),
PRIMARY KEY(id_artista)
)
Here the genres
CREATE TABLE generoMusica(
id_genero SERIAL,
nome_genero VARCHAR(20),
PRIMARY KEY(id_genero)
)
Here the table responsible for making the connection between the tables
CREATE TABLE genero_artistaMusica(
id_artista INT,
id_genero INT,
CONSTRAINT pk_genero_artista_id_artista PRIMARY KEY(id_artista,id_genero),
FOREIGN KEY (id_genero)
REFERENCES generoMusica(id_genero),
FOREIGN KEY (id_artista)
REFERENCES artistaMusica(id_artista)
)
Some points:
The relationship that I created would be like this, an artist may have no or several genres, and a genre may have no or multiple artists.