Assignments
Most of the assignments in this course will be related to your own database and exercises to familiarize you with the systems that we will be using. A second set of assignments will involve the use of an existing database to answer a set of queries, or to modify the database. The same database (called "Diveshop") will be used for the second set of assignments. We will discuss these assignments further in class.
Although there are no formal laboratory sessions scheduled for this course, it should be obvious that you will need to spend a lot of time on your computer to accomplish the assignments.
Assignment 1
Due Thursday Sept. 13
Using your own copy of the Diveshop MySQL database, create queries that produce the answers to the following questions (DiveShop Queries, below). The results should contain only the answers requested -- plus evidence to support them -- and no more (see below).
The Diveshop database for MySQL can be downloaded HERE.
See the MySQL Tutorial - including
phpMyAdmin
created by Kevin Heard, if you have any trouble with the
assignment. This tutorial shows (among other things) how to load the
Diveshop database into your MySQL account so that you can use it for
this assignment. See also clarifications below.
For MySQL the phpMyAdmin program can be used to access your database (Note that the database must have been previously set up for you and you have both an
iSchool account and database name and password sent to you by Kevin)
For more information on SQL consult Chapter 6 (particularly the section on the SELECT command) in the Hoffer textbook. Also, the MySQL reference manual is available online at this site.
As a reminder, the basic form of the SQL Select command is:
SELECT attrname1[, attrname2,... attrnameN]
FROM table1[, table2,... tableM]
[WHERE table1.attrnameX = 'value'
[AND table2.attrnameY = table1.attrnameY AND ...]]
[ORDER BY tableM.attrname1 ASC, ... DESC] ;
The brackets indicate optional parts that may not be needed depending on the query.
To do the queries you will need to become familiar with the structure of the DiveShop database and how individual relations are linked. The ER diagram linked below should should help with this. To link relations (tables) in an SQL SELECT command you simply need to have statement like "table2.attrnameY = table1.attrnameY" where attrnameY is the name of the common attribute that links the relations (such as "Destination_No" linking the DEST and SITES tables could be specified as "DEST.Destination_No = SITES.Destination_No").
We will also be reviewing how to use phpMyAdmin and do SQL queries in class.
DiveShop Queries
- How many tons was the sunken ship Delaware?
- What is customer Karen Ng's address?
- At what destination and site(s) might you find a Spotted Eagle Ray?
- Where (what destination) is the site Palancar Reef?
- What sites might Lorraine Vega dive on her trip?
- Keith Lucas wants to see a shipwreck on his trip. Is he going to the right place?
- What equipment is Richard Denning getting?
- What is the cost of the equipment rental for Louis Jazdzewski.
ER diagram of the DiveShop Database
- The Database is available from the course web site (click here to download it)
- Download your own copy
- For each of the questions create a query in phpMyAdmin.
- Create a document (Word, etc.) containing
- The query being answered
- The results of your query cut and pasted from phpMyAdmin
- Due Thursday Sept. 11 - bring a printed copy and turn it in to me before the beginning of the class
A couple of clarifications:
For the last question, we are asking you how much Louis Jazdzewski is PAYING for the stuff he is renting. (Keep in mind that Louis might be renting more than one of some of the items and we are interested in the total amount he is paying.) We are not asking you what was the "cost" of those items to DiveShop or what the sale price of those items would have been if they were sold rather than rented. Note that the last two numbers would naturally be higher than the rental price.
If you ever get more than a full page of results for your query, you are probably doing something wrong. Most likely you are searching two disconnected tables. All the tables that are a part of your query must be connected. See the ER diagram to see how the tables are linked.
You may get zero results in response to some your queries since some combinations just don't exist. This may mean that the answer the question really is "none/nobody/nowhere" etc. Or it may mean that you misspelled a name or set a wrong constraint.
If you wish to try the Access Database in addition to, or instead of MySQL the following information should help:
Using the Diveshop Access database, create queries that produce the answers to the above questions. The results should contain only the answers requested -- plus evidence to support them -- and no more (see below).
The Diveshop database for access can be downloaded HERE.
The Access program itself is part of Microsoft Office Professional, and is available on the School's shared PCs (in the student areas and 2 in room 210). It is also available as part of Microsoft Office Professional Plus software for PCs available to students and faculty on campus. Click here to see how to download. NOTE: The Mac version of Office does not include Access.
Assignment 2
Due Thursday Sept. 20
Personal Database Project Design
The following information should be turned in for the preliminary design of your personal database project.
A written description of the data you will be using for the database, and what uses you might expect the database to have (2-4 pages). This should include information about the source of the data used, the purposes for which it will be used, any issues or requirements of the database, etc.
A preliminary data dictionary for the entities and attributes and format of the data elements of the database. You should have at least 5 entities with some logical connections between them. The data dictionary consists of all of the attributes that you have identified for each entity, along with indication of whether the attribute is a primary key (or part of a primary key), and what format the data will be (e.g.: text, decimal number, integer, etc.)
An entity-relationship diagram of the database OR a UML diagram.
These will be preliminary design specifications, so do not feel that you must follow everything that you describe here in the final database design.
The report should be printed and is due at the beginning of the class.
Assignment 3: MySQL Commandline Diveshop Queries
Due Thursday Oct 25th
MySQL Setup
Connecting to MySQL on Harbinger (or follow the instructions in the tutorial by Kevin Heard on the web site).
From a Mac, start a Terminal and use "ssh yourischoolid@ischool.berkeley.edu" to login to the Harbinger server where MySQL is located.
From a PC, use a secure shell client like PuTTY (PuTTY is available from /softdist on the school's internal web servers.)
SSH will prompt you for your password for Harbinger (use your ischool password).
You can also login to harbinger from anywhere over the network using any SSH client.
Making queries with mysql
At the unix command prompt enter "mysql -p yourMySQLusername" to start interacting with MySQL:
harbinger:~ --> mysql -p ray
Enter password:
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 788010
Server version: 5.0.45 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
At the "mysql>" prompt you can start entering SQL commands.
Enter "edit" at the mysql> prompt to go into your default editor (PICO is the default). When you save and exit from the editor, the edited query will be returned in the mysql buffer. Alternatively, you can save your queries in a file on your desktop/laptop and copy and paste them back and forth between the file and the ssh prompt.
Be sure to end each SQL command with a semicolon.
To see what diveshop tables are available, submit the command:
show tables;
To see the fields for a particular table issue the command
describe tablename;
where "tablename" is replaced with the name of the table you are interested in.
You are also welcome to use the interactive phpMyAdmin to do this (or any of the the other steps), as described in Kevin Heard's tutorial.
Capturing Output
When you run a query, you are likely to see rather messy output, e.g.:
mysql> select * from SITES;
+---------+----------------+---------------------+----------------+------------+----------------------+-----------------------+----------+---------+---------------+--------------+---------+--------------+
| Site_No | Destination_No | Site_Name | Site_Highlight | Site_Notes | Distance_from_Town_m | Distance_from_Town_km | Depth_ft | Depth_m | Visibility_ft | Visibility_m | Current | Skill_Level |
+---------+----------------+---------------------+----------------+------------+----------------------+-----------------------+----------+---------+---------------+--------------+---------+--------------+
| 1001 | 1 | Palancar Reef | Reef | NULL | 10 | 16.09344 | 100 | 30.48 | 150 | 45.72 | Strong | Intermediate |
| 1002 | 1 | Santa Rosa Reef | Reef | NULL | 8 | 12.874752 | 80 | 24.384 | 150 | 45.72 | Strong | Intermediate |
| 1003 | 1 | Chancanab Reef | Reef | NULL | 4 | 6.437376 | 60 | 18.288 |
...many lines skipped...
About the only way to capture the results and make them pretty is to use the "tee" command to put the output into an external file and then use an editor to modify it.
mysql> \T MYSQLOUTPUT
Logging to file 'MYSQLOUTPUT'
-> select * from SITES;
... lots of lines like above ...
mysql> \t
Outfile disabled.
mysql> \q
Bye
harbinger:~ --> more MYSQLOUTPUT
mysql> select * from SITES;
+---------+----------------+---------------------+----------------+------------
+----------------------+-----------------------+----------+---------+----------
-----+--------------+--------
... etc. ...
This MYSQLOUTPUT file can be edited in any editor you prefer (it is just a text file)
New Diveshop Questions
What are the names and addresses of the diveshop customers who are renting masks?
What are the names of the wildlife that Mary Rioux might see on her trip. Are there any Shipwrecks there (give names)?
What sunken ships might be candidates for treasure hunters whose destination is New Jersey?
Who is paying the maximum amount for single type of rental equipment (use price * quantity to determine amount)?
At how many sites might you see a "Nassau Grouper"?
What are the names of customers who are paying in cash?
Produce a list of all equipment being rented for a dive vacation that costs more than $30000, make the list in descending order of the rental price of the equipment.
Who is renting teal colored equipment? (see DIVESTOK.Description)
Which locations have an avg temperature of more than 75 degrees Farenheit and a travel cost of under $4000?
Make up two queries of your own and run them turn in the queries and the results.
You can also create an SQL command file that contains multiple SQL and mysql commands. The command file contents might look like the following:
\T myoutputfile
select Ship_Name, Tonnage from
SHIPWRCK where Ship_Name like 'Delaware'
\p
\g
...
\t
The "\p" command prints the current command in full (so it can be captured to the "myoutputfile" file along with the query results). The "\g" command runs the query (like a semicolon).
A command file like the one above can be created in a text editor (be sure to save as a plain text file). To run a command file like this one, which already includes the commands to capture the results for further editing or printing, issue the commands:
mysql> \. commandfilename
Where "commandfilename" is the name you saved the command file as.
Turn in the edited version of your commands to answer the questions above from the Diveshop database, including the SQL commands used to obtain your results.
NOTE: Examine the questions carefully - if it asks for something that is rented be sure to verify that an item is a rental and not a sale or you will have wrong answers
Assignment 4
Due Thursday Nov. 8
Personal Database Midterm Report
This is to be a formal report. It should be printed and turned in. Because this is a continuation and expanded version of Assignment 2, you should be sure to remedy any problems pointed out in that assignment, and also describe any design changes made since then. The instructions below include description of what is wanted depending on whether you will be using Access, MySQL or some other database system for your project. You only need to use one database system and provide the information appropriate for that system. The report should include the following information:
Database description -- This should be 4-6 pages describing the database, the organizational (or personal) context for which it is being designed, and the uses for it. The description can incorporate the previous design description from the preliminary design report, but should be more comprehensive and reflect the ongoing design. You should also describe features and changes that you plan to add to the current version for the final version.
Data Dictionary -- For MySQL, you can use the "DESCRIBE" command for each table to generate the same kind of information based on the tables you have created. Or, you can have a manually maintained document with this information, just be sure that it includes what table the data element is associated with, its data type, size and whether it is a primary or foreign key or other constraints (such as NOT NULL or a CHECK test).
Relationships Diagram -- For MySQL you will need to generate an up-to-date ER diagram (note that the tables in ER diagram SHOULD match those in the Data Dictionary.)
Sample queries and results -- Include at least 3 queries of your database that demonstrate how it c an be used. The report should include the SQL form of the query and the table result from running the query. This implies, of course, that you will have created the database and put at least part of your data into it.
Sample forms -- For MySQL include the web pages you intend to use for data input and output. These need not be complete for this report, and it is OK to use initial mockups that may not be working yet. If the system you are using has forms other than web pages (like the forms in Access) provide screen shots of those.
Sample reports -- Create at least 3 reports showing information from tables and queries of your database. Print the reports and include them. For MySQL create and use SQL scripts (or PHP Scripts) to generate the reports. (Reports usually are intended to be printed documents, typically showing summary information for the database, or breakdowns such as numbers of customers by state, total sales by state or region, average sales per customer, etc.)
Final project
Information on the final project and report is in the FINAL page.