CS 348 Database Systems - Sample Exam 1
Each question is worth 4 points. You may use
the MySQL command line client.
You may not use any other materials, files, or notes, etc.
Make sure you write non-SQL answers in the correct
order in your blue exam booklet.
This exam doesn't have any questions about ER diagrams or Database Design
(Ch 7). That is because
when this exam was given I had not covered them yet. I moved
ER diagrams and database Design topics earlier in the course, so expect the
exam to have some ER
diagram questions and questions about Database Design (Chapter 7).
Review practice problem 7.1 (answer is online at
db-book.com.)
Review terminology on page 315.
Consider the following relational database that represents, books, publishers, and books published by publishers.
| BNO |
Title |
Author |
Date |
Edition |
| 231 |
The Soul of a New Machine |
Tracy Kidder |
1981 |
1 |
| 77 |
Programming Pearls |
Jon Bentley |
2000 |
2 |
| 23 |
Programming Pearls |
Jon Bentley |
1981 |
1 |
| 2 |
Tess of the d'Urbevilles |
Thomas Hardy |
1850 |
1 |
books
| PNO |
Publisher |
City |
Web Site |
| 1 |
Back Bay Books |
Boston |
backbay.com |
| 2 |
Addison Wesley |
New York |
addisonwesley.com |
| 3 |
Modern Library |
London |
randomhouse.com |
| 4 |
Penguin |
New York |
penguin.com |
publishers
| PNO |
BNO |
Pages |
Copyright |
| 1 |
231 |
293 |
1981 |
| 2 |
77 |
235 |
2001 |
| 2 |
23 |
200 |
1980 |
| 3 |
2 |
565 |
2001 |
| 4 |
2 |
540 |
1990 |
publishes
-
If a book b is published by publisher p then
b is in the books relation, p
is in the publishers relation,
and a row is added to the publishes relation.
-
The date in the books relation represents the year when the
book was originally issued.
-
The date in the publishes table represents the copyright
date when that particular publisher issued it.
- BNO numbers are unique book identifiers (similar to an ISBN number)
- PNO (publisher numbers) are unique publisher identifiers.
Part 1
-
Does this database schema allow for a book to have more than one publisher?
Explain why or why not using an example.
-
Does this database schema allow for a book to be currently out of print (not currently being published)?
Explain why or why not using an example.
-
List three super keys of the books relation.
-
List all candidate keys of the books relation.
-
(True/False) Consider the statement: It is possible that a relation might not have a super key.
In this case the database designer must
add an attribute that gives the relation a super key.
Write true or false in the blue exam book and briefly explain your answer.
-
List all of the candidate keys of the publishes relation.
-
List all of the super keys of the publishes relation.
-
What two meanings best describe a null web site value in the publishers table?
-
Is SQL's "order by" clause part of the relational algebra? Explain why or why not.
-
In terms of the JDBC what purpose does the class
ResultSet serve? (Don't use the term "result set" in your answer)
-
In terms of the JDBC what purpose does the class
ResultSetMetaData serve? (Don't use the
term "meta data" in your answer.)
- Outline the best strategy to handle publishers that have more than one web site.
-
List all of the foreign keys in the database. Be explicit by naming the referencing
and referenced relations and the appropriate attributes.
-
What is the relational schema for this database? Use the proper notation for specifying a schema.
-
Are there any attributes in the database that could be considered logically non-atomic? Briefly explain why or why not.
-
Assuming we have the tables above, inserting the tuple
(4,83,200,1990) into the
publishes table failed.
Why did this happen? What database principle was violated?
-
Does the SQL statement
select title,author from books;
evaluate to a relation? Briefly explain.
-
Write a relational algebra expression that finds all books currently being published.
The resulting relation should have attributes title, author, and publisher.
Part II - SQL Queries
-
Write an SQL expression that lists all titles by Jon Bentley.
-
Write an SQL expression that evaluates to the union of the author and publisher attributes.
-
Write an SQL expression that computes the set difference of the date and copyright attributes,
date - copyright.
-
Write an SQL expression that computes the set intersection of the date and copyright attributes.
-
Write an SQL expression that lists each book with its publisher. The resulting table should have attributes title, author, and publisher.
-
Write an SQL statement that lists all books that have the same title but different authors.
-
Write an SQL statement that lists the title and author of the book that has the most number of pages.
-
The SQL statement
select count(distinct title) from books;
lists the number of different book titles
and evaluates to the scalar 3 in the example tables above. Suppose that putting the distinct keyword
in the count expression was not supported, write another SQL statement that does the same thing.
-
Write an SQL statement that lists all of the publishers that are in a city with two or more publishers.
-
Write an SQL statement that lists all of the book titles that were originally
issued after every book by Jon Bentley.
-
Write an SQL statement that lists book titles that are currently out of print.