2011 2012 Normalization SQL Sol
2011 2012 Normalization SQL Sol
Use the following description and the three tables to answer parts (A) and (B) of this question.
A transport company provides a number of trucks for cartage purposes. These trucks are hired by
people for a number of different reasons, for example, for carting household items when moving from
one house to another.
The trucks operate from a base, which is managed by at least one employee of the company. A truck
may operate from one or multiple bases over a period of time. A base will have at least one truck at any
given time.
The company hired a database designer to create a MS Access database that could be used by the
company to store details about the trucks. The implemented MS Access database contains three tables,
which are provided together with the relational schema in Figure 1.
Base
Base City State Area Code Phone Manager
501 Murfreesboro TN 615 123-4567 or 123-4577 Andrea D. Gallager
502 Lexington KY 568 234-5678 or 234-5699 Andrea D. Gallager
and
Maria J. Talindo
503 Cape Girardeau MO 456 345-6789 Maria J. Talindo
504 Dalton GA 901 456-7890 Peter F. McAvee
Truck
Truck # Base Base City Base Phone Truck Miles Serial Num
Type
1001 501 Murfreesboro 123-4567 or 123- 1 32123.5 AA-322-12212-W11
4577
1002 501 Murfreesboro 123-4567 or 123- 1 76984.3 AC-342-22134-Q23
4577
1002 502 Lexington 234-5678 or 234- 1 76984.3 AC-342-22134-Q23
5699
1003 501 Murfreesboro 123-4567 or 123- 2 12346.6 AC-445-78656-Z99
4577
1003 503 Cape Girardeau 345-6789 2 12346.6 AC-445-78656-Z99
1005 503 Cape Girardeau 345-6789 2 45673.1 FR-998-32245-W12
1006 501 Murfreesboro 123-4567 or 123- 2 93245.7 AD-456-00845-R45
4577
1006 503 Cape Girardeau 345-6789 2 93245.7 AD-456-00845-R45
1
Truck Type
Type Description
1 Single box, double-axle
2 Single box, single-axle
3 Tandem trailer, single-axle
Figure 1
(A) Discuss some problems with the design of above database and provide examples of the
problems that you have identified. (4 marks).
Ans:
1. Redundancy:
a. The truck details are repeating the truck table because a truck can operate
from multiple bases.
b. The base details are repeating in base and truck tables.
2. Multi-valued attributes: Base phone and Base Manager are both mult-values attributes
3. Attribute Naming: The names of the attributes do not follow a particular format.
2
(B) The current database has three tables. Redesign, that is normalize, the database so that all the
tables are in 3NF and create the dependency diagrams for all the tables in your re-designed
database. Use the primary keys identified in the relational schema for the normalization
process. (14 marks)
3
Question 24 – Structured Query Language (17 marks)
Use the following description and the ERD given below (see Figure 2) to answer parts (A) to (E) of this
question. Write SQL statements to answer each part and your SQL statement should be written for a
MySQL database.
You are given a database that is used by a video library to store data about movies, copies of each
movie, borrowers, and renting of the movies. A movie can have one or more copies. Each copy can be
rented by one of more borrowers.
Figure 2
4
(A) List the details of all borrowers, sorted by their last name in increasing order. (2
marks)
select *
from borrower
order by brw_lname;
(B) List the number and names of all borrowers that have not borrowed any movies. (3
marks)
select b.brw_num,
from borrower as b
rental);
(C) List the code(s), name(s) and the price of the most expensive movie(s) [Hint: use the
movie_charge column]. (3 marks)
from movie
where movie_charge in
5
(D) List the movie code, name and the number of copies of each movie that has more than two
copies. (4 marks)
(E) List the movie code and name of all movies where at least one copy of the movie has never
been borrowed. (5 marks)
from movie
where movie_code in
6
SELECT distinct movie_code,movie_name
7
Semester 1, 2011Final Exam
Use the following description and the two tables to answer parts (A) to (C) of this question.
A small software development firm uses the following two tables to store details about the software
development projects the firm undertakes, the employees who worked on the projects, and the project
manager. For each employee that worked on the project, the employee’s details, the dates when the
employee worked on the project, and the total hours, hourly rate and total payment is recorded for
each day the employee worked on a particular project. For the project manager, only the manager’s
employee number is recorded as the Manager #, and the manager’s name is not recorded.
The employee details are stored in a separate table. The two tables are shown below. The first table is
the Project table, while the second one is the Employee table.
Project
Project Number Title Emp Name Work Date Hours Hourly Total Manager
# Worked Rate Payment #
15 Evergreen 103 June 04-Mar-04 2.60 $84.50 $219.70 105
Arbough
15 Evergreen 101 John News 05-Mar-04 3.60 $105.00 $378.00 105
15 Evergreen 103 June 05-Mar-04 1.90 $84.50 $160.55 105
Arbough
15 Evergreen 105 Alice 05-Mar-04 2.00 $105.00 $210.00 105
Johnson
15 Evergreen 102 David Senior 06-Mar-04 3.80 $96.75 $367.65 105
15 Evergreen 101 John News 06-Mar-04 2.30 $105.00 $241.50 105
15 Evergreen 103 June 06-Mar-04 3.00 $84.50 $253.50 105
Arbough
22 Rolling 113 Delbert 05-Mar-04 2.50 $48.10 $120.25 113
Tide Joenbrood
22 Rolling 105 Alice 05-Mar-04 5.20 $105.00 $546.00 113
Tide Johnson
22 Rolling 104 Anne 06-Mar-04 2.60 $96.75 $251.55 113
Tide Ramoras
22 Rolling 111 Geoff 06-Mar-04 4.00 $26.87 $107.48 113
Tide Wabash
22 Rolling 105 Alice 07-Mar-04 2.70 $105.00 $283.50 113
Tide Johnson
22 Rolling 106 William 07-Mar-04 2.40 $35.75 $85.80 113
Tide Smithfield
25 Starflight 101 John News 05-Mar-04 1.70 $105.00 $178.50 101
25 Starflight 114 Annelise 06-Mar-04 1.80 $48.10 $86.58 101
Jones
25 Starflight 114 Annelise 07-Mar-04 3.40 $48.10 $163.54 101
Jones
8
Employee
Emp # Name Hire Date Job Code Job Desc Job Hourly
Rate
106 William Smithfield 22-Jun-03 500 Programmer $35.75
107 Maria Alonzo 10-Oct-91 500 Programmer $35.75
102 David Senior 12-Jul-87 501 Systems Analyst $96.75
104 Anne Ramoras 15-Nov-85 501 Systems Analyst $96.75
108 Ralph Washington 22-Aug-89 501 Systems Analyst $96.75
109 Larry Smith 18-Jul-95 501 Systems Analyst $96.75
115 Travis Bawangi 25-Jan-90 501 Systems Analyst $96.75
101 John News 08-Nov-98 502 Database Designer $105.00
105 Alice Johnson 01-Feb-91 502 Database Designer $105.00
103 June Arbough 01-Dec-94 503 Electrical Engineer $84.50
110 Gerald Olenko 11-Dec-93 505 Civil Engineer $55.78
111 Geoff Wabash 04-Apr-89 506 Clerical Support $26.87
112 Darlene Smithson 23-Oct-92 507 DSS Analyst $45.95
113 Delbert Joenbrood 15-Nov-94 508 Applications Designer $48.10
114 Annelise Jones 20-Aug-91 508 Applications Designer $48.10
117 Angie Williamson 19-Jun-94 509 Bio Technician $34.55
116 Gerald Pratt 05-Mar-95 510 General Support $18.36
118 James Frommer 04-Jan-04 510 General Support $18.36
9
(B) The current database has two tables. Redesign, that is normalize, the database so that all the
tables are in 3NF and create the dependency diagrams for all the tables in your re-designed
database. A database designer has identified the following primary keys for the above two
tables:
10
(C) Briefly explain when 4NF is violated. (2 marks)
Fourth normal form is violated when the table has multiple independent multi-valued attributes.
However, these multi-valued attributes can be determined by a common key.
11
Question 23 – Structured Query Language (28 marks)
Use the following description and the ERD given below to answer parts (A) to (I) of this question. Write
SQL statements to answer each part and your SQL statement should be written for a MySQL database.
This database is used by a video library to store data about movies, copies of each movie (video),
membership, and rental records of the movies. A movie can have one or more copies. Each copy can be
rented by one or more members. The movie copy record is stored in the Video table. Each movie has a
particular price scheme and all price schemes are included in the Price table.
Price Movie
PK Price_Code SMALLINT PK Movie_Num INTEGER
Detail_Fee DECIMAL(5,2)
Detail_DueDate DATETIME Video
Detail_ReturnDate DATETIME
Detail_DailyLateFee DECIMAL(5,2) PK Vid_Num INTEGER
Vid_InDate DATETIME
FK1 Movie_Num INTEGER
Rental
12
(A) List the details of all members, sorted by their last name in descending order. (2 marks)
SELECT *
FROM membership
(B) List the number of rental transactions where the video was returned late that is after the
due date. (2 marks)
(C) List the movie number, title, rental fee and late return fee for each movie. Sort the list by
rental fee in increasing order. (3 marks)
ORDER BY price_rentfee
(D) List the movie number and title of the most expensive movie(s). (3 marks)
13
(E) List the number, name (combine first and last names together) and state of all members
that live in the same state as members with member numbers 107 and 106. Do not
include members 106 and 107 in the output. (5 marks)
(F) List the video number, movie number and movie title of all movies that have not been
rented out. (3 marks)
(G) Create a view named moviesales that lists the movie number, title and the total amount of
sales for each movie. Include those movies that have not been rented. Exclude any late
return penalty that may have been incurred as a result of the member returning the movie
late. (5 marks)
14
(H) Write the UPDATE statement to update the first name of the member with number 106
from Jane to Jene. (2 marks)
(I) Create a trigger that will automatically update the members balance when the payment
table is updated with the payment records. You can use the following partially complete
trigger definition. (3 marks)
END
15