0% found this document useful (0 votes)
17 views

Database Asignment 3

This document appears to be a homework assignment for a database organization course. It provides the schema for a sample database of recipes and ingredients and poses 13 questions for students to answer using relational algebra expressions. The questions involve retrieving recipes and their ingredients, food items and their properties, calculating totals and averages across the data. The document provides hints on the database schema and example instance to help students structure their relational algebra solutions.

Uploaded by

Edward Nsubi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Database Asignment 3

This document appears to be a homework assignment for a database organization course. It provides the schema for a sample database of recipes and ingredients and poses 13 questions for students to answer using relational algebra expressions. The questions involve retrieving recipes and their ingredients, food items and their properties, calculating totals and averages across the data. The document provides hints on the database schema and example instance to help students structure their relational algebra solutions.

Uploaded by

Edward Nsubi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 7

Name CWID

Homework Assignment
1

September 16th, 2014

CS425 - Database Organization


Results

Please leave this empty!


1.1 1.2 1.3 1.4 1.5 1.6

1.7 1.8 1.9 1.10 1.11 1.12 1.13 Sum


Instructions
• Try to answer all the questions using what you have learned in class

• When writing a query, write the query in a way that it would work over all possible database
instances and not just for the given example instance!

• Some questions are marked as bonus. You do not have to answer these questions to get full points for
the assignment. However, you can get bonus points for these questions!

Consider the following database schema and example instance:

ingredient
recipe foodItem ounces
Pasta and Meatballs Pasta 50
recipe Meatballs 10
Pasta and Meatballs
name inventor kitchen Pasta and Meatballs Tomato Sauce 5
Pasta and Meatballs Le cook Italian Pasta and Meatballs Onions 1
Cheese Soup The french French Cheese Soup Onions 4
Burger Cowboys American Cheese Soup Cheese 15
Cheese Soup Bread 20
Burger Bread 10
Burger Ground Beef 20

foodItem
item type calories stock
Pasta Wheat product 20 foodItem shop price
Meatballs Meat 40 Pasta Aldi 5
Tomato Sauce Sauce 5 Meatballs Aldi 10
Onions Vegetables 1 Tomato Sauce Aldi 3
Cheese Diary 30 Tomato Sauce Walmart 3
Bread Wheat product 25 Cheese Treasury Island 15
Ground Beef Meat 45

Hints:

• Underlined attribute form the primary key of a relation

• The attribute recipe of relation ingredient is a foreign key to relation recipe. The attribute foodItem of
relation ingredient is a foreign key to relation foodItem.

• The attribute foodItem of relation stock is a foreign key to relation foodItem.

DB - Fall 2014: Page 2 (of 7)


Question 1.1.1 (6 Points)
Write a relational algebra expression that returns the food items required to cook the recipe “Pasta and Meat-
balls”. For each such food item return the item paired with the number of ounces required by the recipe.

Question 1.1.2 (6 Points)


Write a relational algebra expression that returns food items that are sold at “Aldi” and their price.

Question 1.1.3 (6 Points)


Write a relational algebra expression that returns food items (item) that are of type “Wheat product” or of
type “Meat” and have at least 20 calories per ounce (attribute calories).

DB - Fall 2014: Page 3 (of 7)


Question 1.1.4 (9 Points)
Write a relational algebra expression that returns the items and their price for all items of type “Wheat
product” sold at Aldi.

Question 1.1.5 (9 Points)


Write a relational algebra expression that returns the names of all recipes that contain meat products (food
items of type “Meat”).

Solution

Question 1.1.6 (10 Points)


Write a relational algebra expression that returns all recipes that contain both “Onions” and “Cheese”.

Solution

DB - Fall 2014: Page 4 (of 7)


Question 1.1.7 (10 Points)
Write a relational algebra expression that returns the food items that are ingredients for “Cheese Soup” but
not for “Burgers”.

Question 1.1.8 (7 Points)


Write a relational algebra expression that returns the total number of ounces for all ingredients per recipe.

Question 1.1.9 (10 Points)


Write a relational algebra expression that returns the average price of food items per type. For example, this
expression should return tuples like (Wheat product, 34.5).

DB - Fall 2014: Page 5 (of 7)


Question 1.1.10 (14 Points)

Write a relational algebra expression that returns the number of food item types for which the average
calories for all food items of this type is higher than 40.

Question 1.1.11 (13 Points)

Write a relational algebra expression that returns the total calories per recipe (assume that calories in the
foodItem table are given per ounce).

Question 1.1.12 (BONUS QUESTION) (5 Points)

Write a relational algebra expression that returns the cheapest price for making the recipe “Burger”. Assume that
the price in the stock table is given per ounce. Also assume that there might be more than one entry for each food
item (e.g., bread and ground Beef) in the stock table, i.e., a food item may be sold by different shops.

Solution

DB - Fall 2014: Page 6 (of 7)


Question 1.1.13 (BONUS QUESTION) (5 Points)

Write a relational algebra expression that returns all recipes that can be cooked from ingredients bought
from a single shop.

DB - Fall 2014: Page 7 (of 7)

You might also like