Open Notes, Open Books
The exam consists of
problems
Answers not appearing in designated spaces WILL NOT be graded
Problem #1 (10 points)
Draw an ER diagram for the following application of a database.
A bank has a name, numerical code, and address. A code uniquely identifies the bank.
A bank branch has a numerical code and address. The code provides an identification for a branch of a bank.
Branches of different banks need not have different codes.
An account has a numerical code, type (saving or checking), and balance
A loan has a numerical code, balance, and interest rate
A customer has a social security number, name, and address.
Each branch belongs to a bank.
Each account is held by a bank branch and owned by a customer
Each loan is provided by a bank branch and owed by a customer
Money of a specified amount can be transfered between a loan and a saving or a checking account
Problem #2 (10 points)
Consider the following relations.
EMPLOYEE
SSN
Name
DeptNum
111
Aaa
2
222
Bbb
1
333
Ccc
2
444
Ccc
2
555
Ddd
3
DEPARTMENT
Num
DeptName
MgrSSN
1
Xxx
222
2
Yyy
111
3
Zzz
222
Answer the following questions based on the above data.
If the issue of foreign keys is ignored, what are the possible single-attribute keys for the EMPLOYEE table and for
the DEPARTMENT table?
What are the possible single-attribute foreign keys for the EMPLOYEE table and for the DEPARTMENT
table?
What is the outcome of the OUTER NATURAL JOIN operation on the relations
and
.
Problem #3 (10 points)
Consider the following schema.
A dancer can like many songs and a song can be liked by many dancers. A dancer can frequent many discos, and a
disco can be frequented by many dancers. A disco can play many songs, and a song can be played by many
discos.
Write a relational algebra query for the following case: Find the dancers who like only songs that none of the discos
play
Write a relational algebra query for the following case: Find the dancers that like the most popular songs (i.e., the
songs liked most by the dancers)
Translate the following SQL query into relational algebra.
select distinct S1.LN from Students as S1, Students as S2 where S1.LN = S2.LN and S1.FN <> S2.FN
Student: Name SSN Attends: SSN Number -------- --------- --------- ------ Tom 123456789 123456789 670 Del 234567891 123456789 680 Dan 891234567 891234567 680 234567891 670 Course: Number Name ------ ---------- 670 database 680 data struc
Show the selection for each of the following queries.
select Student.Name, Course.Name from Student,Course where Course.Name like ’%a__’
select * from Course as S1, Attends as S2 where S1.Number <> S2.Number
select Number from Student, Attends where Student.SSN<Attends.SSN
select SSN, count(*), avg(Number) from Attends S1 where exists (select * from Attends S2 where S1.SSN <> S2.SSN) group by SSN