Professional Documents
Culture Documents
CST363 Final Exam HuyNguyen
CST363 Final Exam HuyNguyen
CST363 Final Exam HuyNguyen
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):
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)
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)
Order# ITEM# ITEM NAME UNIT PRICE ORDER QUANTITY ORDER AMOUNT
0001 100 Tea 1.85 2 3.7
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)
4
> select Item#, Itemname, OrderCount, TotalAmount from Items, Order
(select Order.Item#, sum(orders.Qty) as OrderCount,
sum(Order.Qty*Order.UnitPrice) as TotalAmount from Order)
where Item.Item# = Order.Item#;
SQL> /*Display starbucks store number, city, and the name of its manager */ (5 points)
> select Starbucks.Starbucks#, City, Name, from Starbucks, Employee where
Starbucks.M# = Employee.ID#
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)
> select Name, Employee.Starbucks#, City, Name, from Employee, Starbucks
(select Starbucks#, Starbucks.City, Employee.Name from Starbucks,
Employee where Starbucks.M# = Employee.ID#) where Employee.Starbucks# =
Starbucks.Starbucks#;
SQL> /*Display the item with the highest order quantity. */ (5 points)
> select Order.Item#, Itemname, from Items, Order where Qty = (select max(Oty)
from Order where Order.Item# = Item.Item#)
SQL>/* Add a new item to the Items table. (400, chaiMocha, 4.15) (2 points)
>Insert into Items values (400, chaiMocha, 4.15);
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)
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.
6
(2)Normalize the tables to 3NF. Mark the primary key of each table.
7
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.
- PK = StayID
8
2. Identify all the dependencies in this table. NO NEED to normalize. Feel free to use the
format: OtterID -> Name, status