Exercise 1 - Personal Web Server

advertisement
Take Assessment: Exercise 1
Exercise 1: Relational Databases
Design the following two tables and turn in your submissions in an HTML file named BookPublisher.html.
BOOK:








Primary Author
Title
ISBN
PublisherID
Edition
Date of Publication
Price
Book Description
PUBLISHER:



PublisherID
Name
Address
Part I
1. Identify the keys in your tables as follows. For this exercise, ignore the performance considerations
while choosing your keys.
1. For each table, indicate the Primary Key(s) (PKs). If there is no PK, state so. Fully justify your
answer.
2. For each table, indicate the Alternate Key(s) (AKs). If there is no AK, state so. Fully justify your
answer.
3. For each table, identify the Foreign Key(s) (FKs) and the integrity constraints. Fully justify your
answer.
2. List all columns of your tables, and the domains (the data types and formats) of these columns. Fully
justify your answer.
In an HTML table, list at least 4 rows with valid values in each of the tables. Turn in your submission the file
BookPublisher.html
Part II
Write SQL statements as specified below. Help on setting up your DBMS is available here. Submit your SQL
statements in a file named createDB.sql
1. Write the DDL statements to create the two tables using the CREATE TABLE statement. Be sure to
identify your primary keys and alternate keys in the statement.
2. Write the INSERT statements to insert the 4 rows into each table.
3. Write the SQL statement to retrieve the title and price of all books published by either of two publishers
(say "Addison Wesley" and "McGraw Hill"). In the file Rel-ops.txt, list which relational operations you
used, from among the select/project/join operations, in order to perform this query. Explain the role of
each operation in your query.
4. Write the SQL statement to retrieve the Publisher name of a particular book title (say "Fundamentals of
Database Systems").
Part III
In the file named part3.txt, provide answers to the following questions.
1. In "1.2.2 Relational Operations," there was an example of the set difference operation: the result of r - s
was provided to you. Provide the result of the set difference operation s - r.
2. In the class notes, the following UNION example was discussed. If the UNION were replaced by the
phrase EXCEPT, state in plain English the results that will be retrieved by the query.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
( SELECT
MemNo
FROM
MEMBER, BOOK
WHERE
MemNo = BorrowerMemNo AND
CallNumber = 'QA76.9.D26C66'
)
UNION
( SELECT
MemNo
FROM
MEMBER, BOOK
WHERE
MemNo = BorrowerMemNo AND
CallNumber = 'QA76.9.D7E53'
);
Your submission for this exercise should consist of the following files: BookPublisher.html and createDB.sql,
Rel-ops.txt, and part3.txt.
To help yourself do your best on this assessment, consult this general list of grading guidelines.
Take Assessment: Exercise 2
Exercise 2: SQL
Run the SQL script given to you to create a Library database. Note that each row in the Book table denotes a
book copy. Thus, if the library carries 3 copies of the title "DBMS", there will be 3 rows in the Book table, one
for each copy. Write the SQL statements to do the following against the database (Note: You must express your
query in a single SQL statement for each of the following. However, that statement could have sub-queries.):
1.
2.
3.
4.
5.
6.
7.
8.
List the titles of all books written by "Churchill," along with their Year of Publication.
Retrieve the titles of all books borrowed by members whose first name is "John" or "Susan".
List the names and IDs of all members who have borrowed the "Iliad" and the "Odyssey"—both books.
List the names and IDs of all the members who have borrowed all titles written by "Collins.". Assume
that a member may have borrowed multiple copies of the same title.
Find the phone numbers of all members who have borrowed a book written by an author whose last
name is "Tanenbaum."
Find those members who have borrowed more than 3 books and list their names, IDs, and the number of
books they borrowed. Sort the results in descending order based on the number of books borrowed.
List all members who have not borrowed any book.
List in alphabetical order the first names of all the members who are residents of Pittsburgh (Phone
numbers starting with "412") and who have not borrowed the book titled "Pitt Roads."
To help yourself do your best on this assessment, consult this general list of grading guidelines.
Take Assessment: Exercise 3
Exercise 3: Advanced SQL
For this exercise, we will use the following library schema. It includes information about book titles in the
library, information about library members, about the number of times the books were read by members, about
the suppliers who supply books to the library, and about orders placed with the suppliers. To distinguish the
table names used in this exercise from the table names in other exercise, each table name in this exercise ends
with the character '4'.
Point of clarification: The ReceivedDate column refers to the date when the Order was received by the system
(i.e., recorded in the database). It does not refer to the date a consumer received the items ordered by him.
TITLE4(Name, ISBN, CallNumber, Year, AuthorFName, AuthorLName);
PK(CallNumber)
MEMBER4(LibId, Fname, Lname, Address, PhoneNumber);
PK(LibId)
BOOK4(Book_Id, Edition, Status, BorrowerId, BorrowerDueDate, CallNumber);
PK(Book_Id)
FK(BorrowerId) -> MEMBER4(LibId)
FK(CallNumber) -> TITLE4(CallNumber)
PURCHASE_ORDER4(PoNum, Qty, OrderDate, DueDate, ReceivedDate);
PK(PoNum)
SUPPLIER4(Supplier_Id, Name, Address);
PK(Supplier_Id)
READ_BY4(CallNumber, LibId, TimesRead);
PK(CallNumber, LibId)
FK(CallNumber) -> TITLE4(CallNumber)
FK(LibId) -> MEMBER4(LibId)
ORDERED4(CallNumber, PoNum, Supplier_Id);
PK(CallNumber, PoNum, Supplier_Id)
FK(CallNumber) -> TITLE4(CallNumber)
FK(PoNum) -> PURCHASE_ORDER4(PoNum)
FK(Supplier_Id) -> SUPPLIER4(Supplier_Id)
A series of CREATE TABLE and INSERT statements have been given to create a database. In order not to
erase any existing tables, make sure you run the DDL statements in an empty database (a database that contains
no prior tables).
1. Run the SQL code provided.
2. Write SQL statements (and run them) to delete all tuples in all relations. Capture your SQL statements in
delete_rows.sql
3. Write SQL statements (and run them) to augment (evolve) the database in the following ways. Capture
your SQL statements in alter_tables.sql
1. Create tables for the above relations for which tables have not been created. When deciding the
domains of various columns, pay attention to the INSERT SQL statements mentioned below to
populate the database. If you are using Microsoft Access, please note some of its limitations.
2. Add the constraint that ISBN and Name fields are alternate keys in the TITLE4 table and that
they cannot take a NULL value.
3. Add referential integrity constraints as specified in all the tables.
4. Add the columns "Join_date" and "Gender" to the MEMBER4 relation.
5. Specify that the column "TimesRead" in READ_BY4 relation cannot have negative values.
4. Populate the database according to the INSERT SQL statements given here.
5. Write SQL queries to perform the following commands. Capture all of your SQL commands in a file
called queries.sql
1. Display the ID, first name, and joining date of each member whose ID begins with the letters
"A%B" or "A&B" and who joined the library no later than Nov. 30, 1997.
2. List the name, ISBN, and call number of each title, provided it has been ordered from more than
one supplier and the total quantity ordered is more than 10. The list should be arranged in nonincreasing order of the total quantity ordered.
3. List the IDs and first names of all the members who have read less than 5% of the total number
of books read from the library, in non-decreasing order of the number of books read by each.
4. List in alphabetical order the first names and IDs of all female members of the library who have
read at least one title more than once.
5. List the names of the suppliers and their respective average quantities of title orders received,
whose average quantities of title orders received is more than the average quantity of an order in
the system.
6. List alphabetically the first names and IDs of all the male members of the library who joined
before Oct. 10, 1995, who have read only 5 or fewer different titles, and who have not read the
same title twice or more.
Turn in the following files:
1. delete_rows.sql
2. alter_tables.sql
3. queries.sql
To help yourself do your best on this assessment, consult this general list of grading guidelines.
Take Assessment: Exercise 4
Exercise 4
Design the look of various screens of your E-Store interface by creating all the HTML pages. A description of
the E-Store project you are to implement is given in the Appendix. For this exercise, you should design all the
HTML pages required by the E-Store specified in the Appendix (not just the screenshots given in the
Appendix). Your HTML pages need not contain the code necessary to access the database. However, your html
pages should include all buttons and links that will be clickable in the final implementation of the system. You
can hardcode some dummy data into your HTML pages as placeholders, if necessary. Point the links to the
relevant html pages, such that clicking on the links will bring up appropriate html pages containing some
dummy data. Identify those links and buttons that, when clicked, will initiate access to the database.
For example, among the many html pages you will turn in, let us look at the details of three pages: the search
page, the search-results page, and the book-details page. The search page should have a textbox for the user to
fill in the search criteria, among other things. It should also have a button next to the textbox. In the final
implementation, clicking the button will initiate a database search, but it will not do so after you have completed
this present exercise. For this exercise, clicking the button will simply bring up the search-results page that
contains hard-coded data for some books. Irrespective of the search criteria, the same set of books will be
shown in the search-results page. Each book in the search-results page will be a hyperlink. Clicking the
hyperlink on a book will bring up another page that contains more book details. Again, for this exercise, details
of the same book will be shown, irrespective of the book clicked.
Turn in all of your html pages.
Create a small database using the SQL code given. Design a web site that will search for a member with a
specified phone number. Your site should have 2 pages:
1. One page that has a textfield for the user to type in a member's phone number, and a button to click.
2. Upon clicking, the system should search the database and display all members with that phone number
in a second page.
More help on connecting your database to the web is available from a number of places. Turn in all the relevant
files.
To help yourself do your best on this assessment, consult this general list of grading guidelines.
Take Assessment: Exercise 5
Exercise 5: ER Models
Create the complete ER schema for your E-Commerce database from the specification given in Appendix. Note
that the specification is from a user's point of view, and hence does not tell you all of the keys (primary and
alternate), all of the relationships, and the arity of relationships, etc. You should identify them.
Make reasonable assumptions to make the specification complete. Explicitly state all your assumptions.
EVERY construct in your ER schema should be substantiated by either the specification above or your explicit
assumptions.
Make sure you identify all of the following:



the entity types (identify weak entities)
the attributes in each entity type (identify it also as either single-valued/multi-valued, derived,
simple/composite, etc). Leave the attributes out of the diagram. Instead, list each entity in a textual form,
and beneath each one, list its attributes.
the relationship types (identify the roles, the cardinality constraints, and participation constraints)
Use the ER diagramming notations to draw your schema. Turn in your ER schema in a file named ER.gif, and
the attribute list in a text file named ER.txt
To help yourself do your best on this assessment, consult this general list of grading guidelines.
Take Assessment: Exercise 6
Exercise 6: Normalization
Provide your solution to the following in a file named normalization.txt . Note: The discussion in this exercise is
independent of (i.e., completed unrelated to) the E-Commerce project described in the Appendix.
The following table captures the following fact about an E-Commerce bookstore: the employee whose name is
EmpName and whose ID is EmpID has shipped the order (whose Order Number is OrderNo ) to the address
ShipToAddr on the date ShippedDate. The tracking number for the shipment is TrackingNum. The
TrackingNum is provided by the courier company that picks up the shipment. The bookstore uses only one
courier company. Note that a single order could be split up into multiple shipments based on the availability of
the ordered items. Only one employee handles a shipment. However, multiple employees could handle an order
if the order is shipped in multiple shipments.
SHIPMENT EmpID
1.
2.
3.
4.
5.
EmpName
OrderNo
1234
Joe
223
2134
Jones
224
ShipToAddr
4615 Forbes Ave,
Pittsburgh, PA 15147
4615 Forbes Ave,
Pittsburgh, PA 15147
ShippedDate TrackingNum
12/21/99
12435678
12/25/99
21345678
List the primary key.
List all the FDs.
List all the update anomalies and provide an example of each.
What normal form is the relation in? Explain.
Apply normalization to it incrementally, carrying the normalization process through each of the higher
normal forms possible up to 3NF. That is, if the relation is in an unnormalized form, bring it to the 1st
normal form, then bring the 1st normal form you've just created to the 2nd normal form, and then bring
the 2nd normal form to the 3rd normal form.
For each transformation to the next higher normal form X,
o
o
o
explain the steps you took to bring it to the normal form X
provide the normal form X's table structure, primary key(s), and the FDs
explain why you think it is in the normal form X
That is, if the relation is in an unnormalized form, you would explain the transformation you performed
to bring it to 1st, 2nd and 3rd normal forms. You would also provide the table structure, the primary key
and the FDs for the 1st, 2nd, and 3rd normal forms. You would also provide explanation for why you
believe it is in 1st, 2nd and 3rd normal forms.
You should submit the following files for this exercise.
1. normalization.txt
To help yourself do your best on this assessment, consult this general list of grading guidelines.
Take Assessment: Exercise 7
Exercise 7: ER Mapping
Map your ER schema into a relational database schema, using the mapping algorithm. Express the resulting
relational database schema, using the following notation: PK for Primary Key, AK for Alternate Key, and FK for
Foreign Key with an arrow to corresponding Table(Primary key) as given below. Show the results of your work
for each step of the mapping algorithm. Submit your work in a file called relational-schema.txt.
EMP(SSN, Name, DriverLicenseNo, DeptNo);
PK(SSN)
AK(DriverLicenseNo)
FK(DeptNo) -> Dept(DNo)
Code your relational schema using CREATE TABLE statements. Notice that this set of statements should
specify the integrity constraints: keys, relationships, etc. Submit your CREATE table statements as a text file
named relational-model.sql.
Run your CREATE TABLE statements to create the relational schema.
You should submit the following files for this exercise.
1. relational-schema.txt
2. relational-model.sql
To help yourself do your best on this assessment, consult this general list of grading guidelines.
Take Assessment: Exercise 8
Exercise 8
Complete your E-Commerce project ( as specified in Appendix). It should have all the functionalities mentioned
in the project description document. Turn in all the relevant files and the SQL statements to create your initial
database.
Use "prxyuser" as the username and "prxypass" as the password in your ConnectionString. Name your database
as bookstore.
You can borrow ideas from the library project implementation.
Package and compress all your files into one file using WinZIP, or some other utility or combination of utilities.
tar and gzip are freeware utilities you can download from the web that will help you package and compress
multiple files into one file.
In exam3, you might be asked to extend your E-Commerce project implementation. Instead of extending your
implementation, you could extend the sample library project. Make sure you have the skills to build a webbased database application. The best way to master the skills and be prepared for exam3 is to complete your
project.
To help yourself do your best on this assessment, consult this general list of grading guidelines.
Download