我是 SQL 的初学者,尤其是 TSQL 的初学者。我需要为 SQL Server 2008 编写一个 SP,它将读取所有符合某些条件的记录,然后在不同的结果集中读取它们相关的类别、成分、单位等。为了阅读一个元素,我的 SP 是:
-- Select the recipe
SELECT Recipe.*
FROM Recipe
WHERE Recipe.RecipeId = @RecipeId
-- Select the categories themselves
SELECT Category.*
FROM Category
JOIN RecipeCategory ON RecipeCategory.CategoryId = Category.CategoryId
WHERE RecipeCategory.RecipeId = @RecipeId
-- Select the ingredient information for the recipe
SELECT RecipeIngredient.*
FROM RecipeIngredient
JOIN Recipe ON Recipe.RecipeId = RecipeIngredient.RecipeId
WHERE Recipe.RecipeId = @RecipeId
-- Select the ingredients themselves
SELECT Ingredient.*
FROM Ingredient
JOIN RecipeIngredient ON RecipeIngredient.IngredientId = Ingredient.IngredientId
JOIN Recipe ON Recipe.RecipeId = RecipeIngredient.RecipeId
WHERE Recipe.RecipeId = @RecipeId
-- Select the units that are associated with the ingredients
SELECT Unit.*
FROM Unit
JOIN Ingredient ON Ingredient.UnitId = Unit.UnitId
JOIN RecipeIngredient ON RecipeIngredient.IngredientId = Ingredient.IngredientId
WHERE RecipeIngredient.RecipeId = @RecipeId
我如何将其转换为阅读所有具有Name like '%..%'
由于桌子上有数百万种食谱,我想尽可能高效地完成它。