Skip to content
Advertisement

How to grab the ID of an artist so i can insert the album into the database with the artist’s ID?

Here is my schema:

This is what I’m doing:

Right now I’m inserting into albums by looking at the table for the artist ID and typing manually. How can I do this automatically?

My application will receive the song title, artist name and album name. So it will need to look for the artist ID if the artist exists and if not, create the artist, then grab the ID of said artist and put into the INSERT INTO albums statement.

Advertisement

Answer

One way:

Another way to do multiple albums from the same artist at once. You can just list them in the VALUES definition.

And another way for good measure:

And another way:

Ok, I’ll stop.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement