Thanks. A little more detail. So Ill start at the beginning.
I am trying to do the following:
create a new procedure called AddAlbum. It will take two parameters - ArtistName and AlbumName. I need to check the Artists table to see if an ArtistName exists. If it does not exist, I need to add a new row. I'm attempting the following:
1. Use the COUNT aggregate on table Artists to see how many rows exist for ArtistName. Store the count in a variable called artist_count. This is as far as I've gotten.
2. If artist_count is zero, insert a new row into Artists. Select the LAST_INSERT_ID() into a variable.
3. If artist_count is one, lookup the ArtistID and store it in a variable.
4. Insert a new row into the Albums table.
Here is the code I've got to work so far.
Drop Procedure if exists AddAlbum;//
Create procedure AddAlbum(in_ArtistName Varchar(50), in_Title varchar(50))
BEGIN
Declare Artist_Count int;
Declare artist_id int;
Select Count(*) into Artist_Count From Artists;
END; //
[code]
Am I on the right track and how do you do the If statements?
Before anyone flames me, yes this is a school assignment and I am fully aware of the policy regarding homework but I am so lost on this. Any guidance is appreciated. Thanks in advance for any help.