I’m currently having issues with an objective for an online class I am taking. The objective is below this, The code I’m using along with the error I’m receiving will be below that.
Use a variable to write a procedure called “AddNewAlbum.” This procedure takes at least two parameters – NameOfArtist and AlbumName. The procedure will:
1.Lookup ArtistID from the Artist table, where artist name is NameOfArtist
2.Insert a new row into Albums, using the ArtistID found in step #1 and the AlbumName parameter
For now it is safe to assume the artist exists before you run this procedure (meaning if you CALL AddNewAlbum (‘Bob Dylan’, ‘Street Legal’); then “Bob Dylan” already exists in the Artist table.
CREATE PROCEDURE AddNewAlbum (
NameOfArtist varcahr(50),
AlbumName varchar(50)
)
BEGIN
SELECT ArtistID, ArtistName FROM Artists
WHERE ArtistName = 'NameOfArtist';
INSERT INTO Albums (Title)
VALUES (AlbumName);
END;
//
CALL AddNewAlbum (
"Bob Dylan",
"Street Legal"
);
//
ERROR 1364 (HY000): Field ‘ArtistID’ doesn’t have a default value
^ Is the error I receive. Can anyone see what I am doing wrong? I tried taking the quotations around WHERE ArtistName = ‘NameOfArtist’;
but this did not work.
I’d like to add that it is pulling the Artists name and the ArtistID but is not adding the new row to Albums.
you can use
INSERT INTO...SELECTstatement on this,