Midterm Review Amanda
Midterm Review Amanda
MIDTERM REVIEW
Chapters 1 – 5, 19
M. Amanda Crick
(Uses slides from Fernando Farfan and
Eduardo J. Ruiz
Chapter 1: Overview of
DBMSs
Concepts:
•DBMS
•Relational Model
•Levels of Abstraction
•Data Independence
Exercise 1.1
Problem
Why would you choose a database
•Relationship( •Roles
Set) •One-to-Many
•Primary Key •Many-to-May
•Participation •Weak Entity Set
Constraint •Identifying
Exercise 2.2
Problem
A university database contains information
ssn
courseid
Solution
Solution
ssn semester courseid
semester teaches
courseid Course
Chapter 3: Relational
Model
Concepts:
•Table/Relation •Cardinality
•Relation •DDL
•Attributes/ •Superkey
Domain •Candidate Key
•Relation
•Foreign Key
Instance
•
Exercise 3.12
Problem
Consider the scenario from Exercise 2.2,
ssn
courseid
semesterid
ssn
courseid
semester teaches
courseid Course
Exercise 3.12
Solution
toCREATE
(6) TABLE Teaches
( gid INTEGER,
courseId INTEGER,
semester CHAR(10),
PRIMARY KEY (gid, courseId),
FOREIGN KEY (gid) REFERENCES Group,
FOREIGN KEY (courseId) REFERENCES
Course )
CREATE TABLE MemberOf
( ssn CHAR(10),
gid INTEGER,
PRIMARY KEY (ssn, gid),
FOREIGN KEY (ssn) REFERENCES Professor,
FOREIGN KEY (gid) REFERENCES Group )
Exercise 3.12
Solution
to (6)
n
•Join
Exercise 4.2
Problem
Given two relations R1 and R2, where R1
Problem
1. Find the Supplier names of the suppliers who
Solutio
n
Exercise 4.4
Problem
2. This Relational Algebra statement does not
return anything because of the sequence of
projection operators. Once the sid is projected,
it is the only field in the set. Therefore,
projecting on sname will not return anything.
Solutio
n
Exercise 4.4
Problem
3. Find the Supplier names of the suppliers
who supply a red part that costs less
than 100 dollars and a green part that
costs less than 100 dollars.
Solutio
n
Exercise 4.4
Problem
4. Find the Supplier ids of the suppliers who
supply a red part that costs less than 100
dollars and a green part that costs less
than 100 dollars.
Solutio
n
Exercise 4.4
Problem
5. Find the Supplier names of the suppliers
who supply a red part that costs less
than 100 dollars and a green part that
costs less than 100 dollars.
Solutio
n
Chapter 5: SQL, Null Values,
Views
Concepts:
•DML
•DDL
•Query
•Nested
Query
•Aggregation
Exercise 5.2
Problem
Consider the following relational schema:
Dependency
•BCNF
•3NF
Exercise 19.2
Problem
Consider a relation R with five attributes
Solution
CDE, ACD, BCD
Exercise 19.2
A → B, BC → E, and ED →
A.
Problem
2. Is R in 3NF?
Solution
R is in 3NF because B, E and A are all
parts of keys.
Exercise 19.2
A → B, BC → E, and ED →
A.
Problem
3. Is R in BCNF?
Solution
R is not in BCNF because none of A, BC
the following:
(i) Compute the set of dependencies that hold
over the set and write down a minimal cover.
(ii) Name the strongest normal form that is not
violated by the relation containing these
attributes.
(iii) Decompose it into a collection of BCNF
relations if it is not in BCNF.
Exercise 19.2
F = {AB →C, AC → B, AD → E, B → D, BC → A, E
→ G}.
Problem
a) ABC
Solution
i. R1 = ABC: The FD’s are AB → C, AC → B, BC →
A.
ii. This is already a minimal cover.
iii. This is in BCNF since AB, AC and BC are
candidate keys for R1. (In fact, these are all the
candidate keys for R1).
Exercise 19.2
F = {AB →C, AC → B, AD → E, B → D, BC → A, E
→ G}.
Problem
b) ABCD
Solution
i. R2 = ABCD: The FD’s are AB → C, AC → B, B
→ D, BC → A.
ii. This is already a minimal cover.