I've been creating a recipe database for a class project using SSMS. I have one table with all the recipe names that I'd inserted into a lookup table (RecipeDetails
), but I'd left out their associated IDs, so I wanted to write a bit of code to update my table with those values. I feel like this code should work fine (it seemed to work in the past, but I screwed up something unrelated and had to restore my most recent database backup), but now it just isn't. It says it's affected all the rows I expect it to affect, but those rows still list the RecipeID
as NULL
.
I'm pulling my data from RecipesTable
, which includes the names of each recipe and an ID for each. In RecipeDetails
I have a column for RecipeName
, RecipeID
, Ingredient
, IngredientID
, and an ID for each row in the table. As of now, I have all my recipes in the table, but not their associated ID. I would like to move the ID's over from one table to another.
UPDATE rd
SET rd.RecipeID = rt.RecipeID
FROM RecipeDetail AS rd
FULL JOIN RecipesTable AS rt ON rd.RecipeID = rt.RecipeID
WHERE rt.RecipeName = rd.RecipeName;