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 |
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 |
PNO | BNO | Pages | Copyright |
1 | 231 | 293 | 1981 |
2 | 77 | 235 | 2001 |
2 | 23 | 200 | 1980 |
3 | 2 | 565 | 2001 |
4 | 2 | 540 | 1990 |
Yes, notice book 2 appears twice in the publishes relation.
Yes, in this case the book would not appear anywhere in the publishes relation.
{BNO, Title}, {BNO, Author}, {BNO, Date} are all superkeys, in fact there are many more. Any subset of attributes that contains BNO is a superkey.
There is one candidate key and its {BNO}.
False, since a relation is a set and sets do not contain duplicate tuples then by definition every relation has a superkey that consists of all of the attributes in the relation.
There is one, {PNO, BNO}.
There are four: {PNO, BNO},{PNO, BNO, Pages}, {PNO, BNO, Copyright}, {PNO, BNO, Pages, Copyright}.
Either the publisher does not have a web site, or we don't know what the web site is.
We haven't covered relational algebra in this class. But anyway, the
answer is no,
by definition a relation is a set and a set is unordered, so the
order by
clause has no place in set operations on
relations (relational algebra).
ResultSet
serve?
(Don't use the term "result set" in your answer)
ResultSet
is the JDBC class that represents the output
of an SQL query. The class contains functions for iterating
through the rows and also getting the values of individual
attritbutes in each row.
ResultSetMetaData
serve? (Don't use the
term "meta data" in your answer.)
ResultSetMetaData
is the JDBC class that represents information
about a ResultSet
object. It contains data about the data including
the names of the attributes and the number of attributes in each row, etc.
This would be an example of a multi-valued attribute. We should create another table of website wherethe URL of the web site is the primary key and the publisher number is a foreign key referring to the publisher number in the publishers relation.
The author of a book might best be separated into first and last names.
(4,83,200,1990)
into the
publishes table failed.
Why did this happen? What database principle was violated?
It failed becuase there is no book 83. This would have violated the principle of referential integrity.
select title,author from books;evaluate to a relation? Briefly explain.
The result wold have a duplicate tuple (Programming Pearls, Jon Bentley) and a relation is a set and sets do not have duplicaes so it it does not evaluate to a relation.
Don't bother, we didn't cover relational algebra in any detail.
select title from book where autho='Jon Bentley';
select author from books union select publisher from publishers;
select distinct date from books where date not in (select copyright from publishes)
select distinct date from books where date in (select copyright from publishes)
select title, author, publisher from books inner join publishers inner join publishes using (bno,pno)
select * from books as b1, books as b2 where b1.title=b2.title and b1.author != b2.author
select title,author from books inner join publishes using (bno) where pages = (select max(pages) from publishes);
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.
select count(*) from (select distinct title from books) as temp;
select publisher from publishers where city in (select city from publishers group by city having count(city) >= 2);
select * from books where date > all (select date from books where author = "Jon Bentley")
select title from books where bno not in (select distinct bno from publishes)