Académique Documents
Professionnel Documents
Culture Documents
1
1.1 Given the table structures, answer the following questions (5 points):
1.2 Use relational operators: union, difference, intersect, product, select, project to find out the
following information (15 points):
2
Question 2 (50 points in total)
Items Starbucks Order
Item# Itemname UnitPrice Starbucks# City M# Order# Item# Starbucks# UnitPrice Qty
100 Tea 1.85 1 SJ 001 0001 100 1 1.85 2
200 Latte 2.85 2 SJ 006 0002 100 2 1.85 1
300 Mocha 3.15 3 SD 004 0003 200 3 2.85 2
4 SD 005 0004 200 3 2.85 1
5 SF 003 0005 300 4 3.15 1
0006 300 5 3.15 2
Employee
ID# Name Starbucks#
001 Jason 1
002 Will 1
003 Lisa 5
004 Mary 3
005 Mark 4
006 Holly 2
007 Grace 2
008 Taylor 3
2.1 Locate the following information for each table (10 points)
3
Items
o Item#
o (Itemname, UnitPrice)
Starbucks
o Starbucks#
o (City, M#)
Oder
o Order#
o (Item#, Starbucks#, UnitPrice, Qty)
Employee
o ID#
o (Name, Starbucks#)
all foreign keys, and the attributes they reference in another table.
Items
o No foreign key
Starbucks
o No foreign key
Order
o Order.Item# references Items.Item#
o Order.UnitPrice references Items.UnitPrice
o Order.Starbucks# references Starbucks.Starbucks#
Employee
o Employee.Starbucks# references Starbucks.Starbucks#
SQL> /* Display the order#, item#, item name, unit price, order quantity, sales amount of
all orders */ Note: use alias for output, use the following output as reference. (5 points)
4
Order# ITEM# ITEM NAME UNIT PRICE ORDER QUANTITY ORDER AMOUNT
0001 100 Tea 1.85 2 3.7
SELECT Order#, ItemName, UnitPrice, Qty, Qty * UnitPrice Order Amount
FROM Items, Order
Where Items.Item# = Order.Item#;
SQL> /* Provide a summary of the sales (Display the total order quantity and amount of
each item, including the following information: Item#, Item Name, total order amount,
total sales amount of each item */ (5 points)
SQL> /*Display starbucks store number, city, and the name of its manager */ (5 points)
SQL> /*Display the name of the employee, the store number and city of the starbucks
he/she works for, and the managers name. (5 points)
SQL> /*Display the item with the highest order quantity. */ (5 points)
5
SELECT TOP(5) Item#, Sum(Qty) As TotalQuantity
FROM Orders
GROUP BY Item#
Order by TotalQuantity DESC;
SQL>/* Add a new item to the Items table. (400, chaiMocha, 4.15) (2 points)
SQL> /* Write SQL commands to accept a user input ID# and display all information at
Employee table related to this EmployeeID, like the following */ (10 points)
Please draw ER diagram to define entities and relationships in terms of connectivity and cardinality. NO
need to include attributes of each entity.
3.1 Each employee must have one manager, each manager supervises at least one employee (3 points)
6
3.2 A certificate program has 5 instructors, each can teach 40 students per class maximum. There are 8
courses, each class is taught by one instructor. Each instructor can teach up to 2 classes, or no class at all.
Each student can take more than one class (7 points). Assumption: all eight classes are different.
A+B C, D, E, F, G, H, I
A C, D
B -> E, F
G H, I
A B C D E F G H I
(1)Normalize the above table to 2NF. Mark the primary key of each table.
A B G H I
A C D
B E F
7
(2)Normalize the tables to 3NF. Mark the primary key of each table.
A B G
G H I
A C D
B E F
4.2
The boutique bed and breakfast has many guests. Each guest has a number (num) and name (name).
Number for each guest is unique, name of the guest is not unique since two people can have the same
name. Every time a guest stays at the bed and breakfast hotel, the stay is assigned by a unique stay ID
(stayID). When a guest frequents the hotel, he/she will have multiple stayID. Each stay has a date for
check in and check out. In each stay, the guest will stay more than one night. The price of the room
changes depending on the checkin date.
2. Identify all the dependencies in this table. NO NEED to normalize. Feel free to use the
format: OtterID -> Name, status
8
9