Question: Hello, Please help! Given the below table, please Write query to SELECT ingredients for a recipe. Write query to SELECT kCal content for a recipe

Hello, Please help!

Given the below table, please

Write query to SELECT ingredients for a recipe.

Write query to SELECT kCal content for a recipe

Write query to SELECT the recipes that take less than an hour to make

-- Table "Recipe"

-- Uses Picture, SkillLevel tables

CREATE TABLE Recipe (

RcpRecipeID BIGINT NOT NULL,

RcpName VARCHAR(48) NOT NULL,

RcpDirections VARCHAR(4000) NOT NULL,

RcpPrepTimeMins INT NOT NULL,

RcpCookTimeMins INT NOT NULL,

RcpTotalTimeMins INT NOT NULL,

RcpYieldServingsLow INT NOT NULL,

RcpYieldServingsHigh INT NOT NULL,

RcpCalsPerServing INT,

RcpSource VARCHAR(128),

RcpSkillLevelID BIGINT NOT NULL,

RcpPictureID BIGINT NOT NULL,

RcpCreated DATETIME DEFAULT GETDATE(),

RcpCreatedBy INT,

RcpLastModified DATETIME DEFAULT GETDATE(),

RcpLastModifiedBy INT,

PRIMARY KEY (RcpRecipeID)

);

-- Table "Picture"

-- Stores Recipe pictures

CREATE TABLE Picture(

PictureId BIGINT NOT NULL,

PictureCredit VARCHAR(128) NOT NULL,

Picture IMAGE NOT NULL,

PictureCreated DATETIME DEFAULT GETDATE(),

PictureCreatedBy INT,

PictureLastModified DATETIME DEFAULT GETDATE(),

PictureLastModifiedBy INT,

PRIMARY KEY (PictureId)

);

-- Table "RecipeIngredient"

-- Stores all specific ingredient configurations per recipe (refers to both Recipe and Ingredients tables)

-- Notes: As per John Brandolini's good correction: renamed all fields to start with prefix RcpIng.

CREATE TABLE RecipeIngredient(

RcpIngRecipeIngredientId BIGINT NOT NULL,

RcpIngRecipeId BIGINT NOT NULL,

RcpIngIngredientId BIGINT NOT NULL,

RcpIngAmount VARCHAR(16) NOT NULL,

RcpIngPrepInfo VARCHAR(64) NOT NULL,

RcpIngCreated DATETIME DEFAULT GETDATE(),

RcpIngCreatedBy INT,

RcpIngLastModified DATETIME DEFAULT GETDATE(),

RcpIngLastModifiedBy INT,

PRIMARY KEY (RcpIngRecipeIngredientId)

);

-- Table "Ingredient"

-- Stores all recipe ingredient details for re-use across recipes

CREATE TABLE Ingredient(

IngIngredientID BIGINT NOT NULL,

IngName VARCHAR(64) NOT NULL,

IngDescription VARCHAR(128),

IngCreated DATETIME DEFAULT GETDATE(),

IngCreatedBy INT,

IngLastModified DATETIME DEFAULT GETDATE(),

IngLastModifiedBy INT,

PRIMARY KEY (IngIngredientID)

);

-- Table "SkillLevel"

-- Stores available skill levels -- e.g. high/medium/low or "master chef/sous chef/line cook/server/bus person/plongeur"

CREATE TABLE SkillLevel(

SkillId BIGINT NOT NULL,

SKillDescription VARCHAR(16) NOT NULL,

SkillCreated DATETIME DEFAULT GETDATE(),

SkillCreatedBy INT,

SkillLastModified DATETIME DEFAULT GETDATE(),

SkillLastModifiedBy INT,

PRIMARY KEY (SkillId)

);

-- AppApp Foreign Keys

-- Add [Recipe | Picture] relationship

ALTER TABLE Recipe

ADD CONSTRAINT FK_Recipe_Picture FOREIGN KEY (RcpPictureId) REFERENCES Picture(PictureID);

-- Add [Recipe | SkillLevel] relationship

ALTER TABLE Recipe

ADD CONSTRAINT FK_Recipe_SkillLevel FOREIGN KEY (RcpSkillLevelID) REFERENCES SkillLevel(SkillId);

-- Add [RecipeIngredient | Recipe] relationship

-- Notes: Related RecipeIngredient records should be deleted if parent Recipe record is deleted (as per JohnB)

ALTER TABLE RecipeIngredient

ADD CONSTRAINT FK_Recipe FOREIGN KEY (RcpIngRecipeId) REFERENCES Recipe(RcpRecipeId) ON DELETE CASCADE;

-- Add [RecipeIngredient | Ingredient] Relationship

ALTER TABLE RecipeIngredient

ADD CONSTRAINT fk_ingredient FOREIGN KEY (RcpIngIngredientId) REFERENCES Ingredient(IngIngredientId);

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!