Question 1 Consider the following table (primary key is underlined

Question 1
Consider the following table (primary key is underlined):
(A, B, C, D, E, F, G, H, I)
There exists the following set of additional functional dependencies:
A→D
B → F, G, H
G→H
What is the normal form of the original table?
1NF
If the normal form is not 3NF, convert the table into a set of 3NF tables.
Converted to 2NF:
(A,D)
(B, F, G, H)
(A, B, C, E, I)
Converted to 3NF
(A,D)
(B, F, G)
(G, H)
(A, B, C, E, I)
Question 2
Use the following five tables to answer all questions in this section. The primary keys are
underlined. The foreign keys have the same name as the primary key in another table.
Assume that peerAdvisorID is a reference to another student (the studentid of another student).
Publisher(publishername, address, city, state)
Book(isbn, title, datePublished, publishername)
BookCopy(bookID, isbn, condition, datePurchased, price)
BookCheckout(bookID, studentID, dateIn, dateOut)
Student(studentID, firstname, lastname, city, state, email, peerAdvisorID)
Write SQL commands to do the following tasks.
1. Output the First Name and Last Name for all students from New Jersey.
SELECT firstname, lastname
FROM Sudent
WHERE state = ‘New Jersey’
2. Output the bookid, title, and condition of all book copies.
SELECT bookID, title, condition
FROM Book, BookCopy
WHERE Book.isbn = BookCopy.isbn
3. Output the first and last name of students along with the title of every book they have checked
out.
SELECT firstname, lastname, title
FROM Student, Book, BookCheckout, BookCopy
Where Student.studentID = BookCheckout.studentID AND BookCheckout.bookID =
BookCopy.bookID AND BookCopy.isbn = Book.isbn
4. Output the average price of all books.
SELECT AVG(price)
FROM BookCopy
5. Output the average price of books checked out by a student from New Jersey.
SELECT AVG(price)
FROM BookCopy, BookCheckout, Student
WHERE state = ‘New Jersey’ AND BookCopy.bookID = BookCheckout.bookID AND
BookCheckout.studentID = Student.studentID
6. Output the name of each publisher and the number of books published by that publisher.
SELECT publishername, COUNT(*) AS BooksPublished
FROM Book
GROUP BY publishername
7. Output the name of each publisher and the number of books published by that publisher, but
only for publishers that have published at least 10 books.
SELECT publishername, COUNT(*) AS BooksPublished
FROM Book
GROUP BY publishername
HAVING COUNT(*) >= 10
8. Output the names of all students and the name of their peer advisor.
SELECT A.firstname, A.lastname, B.firstname, B.lastname
FROM Student A, Student B
WHERE A.peerAdvisorID = B.studentID
9. Output the bookid for all book copies that have never been checked out by a student.
SELECT bookID
FROM BookCopy
WHERE bookID NOT IN
(SELECT bookID
FROM BookCheckout)
10. Output the bookID with the highest price.
SELECT bookID, price
FROM BookCopy
WHERE price =
(SELECT MAX(price) FROM BookCopy)
Question 3
Write a script named q3.sql to create the following database. Enforce all primary and foreign keys. Be
careful in the order that you create your tables. Make sure that the price of a book is between 1 and 20.
Make sure that dateOut is always greater than dateIn. Make sure that if a publishername changes in the
Publisher table, it is changed automatically in all relevant records in the Book table. Your script should
also contain a trigger that will add 1 to checkedOut whenever a new BookCheckout record for the book
is inserted. Insert at least 2 publishers, 3 books, 5 book copies, and 8 checkouts.
Publisher(publishername, address, city, state)
Book(isbn, title, datePublished, publishername)
BookCopy(bookID, isbn, condition, datePurchased, price, checkedOut)
BookCheckout(bookID, studentID, dateIn, dateOut)
See file in zip
Question 4
Create an XML file named q4.xml that is the equivalent to the database in question 3. Have at least 2
publishers, 3 books, 5 book copies, and 8 checkouts.
Also create a DTD file named q4.dtd that can be used to validate that XML file. Make sure you use ID
attributes to create primary keys for Publisher, Book, and BookCopy. Also use IDREF attributes for all
foreign keys (what foreign keys you have depend upon the format of the XML file).
See files in zip.
Question 5
Modify the schema file q5.xsd that can be used to validate q5.xml. Your schema file should have the
following features:










A Student can have up to three email nodes.
The condition of a BookCopy must be excellent, good, fair, or poor.
An ISBN of a BookCopy must be 9 digits.
The price of a BookCopy must be between 10 and 50, inclusive.
The DateIn of a BookCheckout must be after December 31, 2010.
The email of a Student must be letters followed by @strose.edu
All StudentID nodes of Student nodes must be unique.
All BookID nodes of BookCopy nodes must be unique.
All BookID nodes of BookCheckout nodes must match a BookID node of a BookCopy node.
All StudentID nodes of BookCheckout nodes must match a StudentID of a Student node.
See files in zip
Question 6
Write an xslt file named q6.xslt that uses q5.xml to print BookID, ISBN, and condition for all books with a
condition of “poor”.
See file in zip.
Question 7
Write an xslt file named q7.xslt that uses q5.xml to print the BookID, DateIn, DateOut, StudentID,
FirstName, and LastName for all book checkouts.
See file in zip.