You will be practising your Basic SQL skills in the form of creating a
Database, Inserting some data and running creating some queries.
Tasks 01 - Setting up
Your Database:
- Go to web.cs.manchester.ac.uk and log in with your University username (i.e. a12345bc)
and password
- Only the lower box “MySQL Database Account”
is relevant. Choose a password, but this should NOT be your university password. Choose
something different and remember it: you will be needing it again. Click “Create
database
account”
- Again, only the “MySQL Database
Account” is relevant. For $database host and $database name, your username will appear
between the quotes.
- Make a note of your credentials and then click on the like:
dbhost.cs.man.ac.uk/phpMyAdmin
and log in with your university username and the new password you have just created.
- Here you can use the SQL Tab to paste in SQL Queries for creating and manipulating your
databases
Tasks 02 - Using a
Larger Database:
Northwind is a sample database distributed with MS Access. It comprises 150K of data. So not
particularly large, but not tiny either.
- Download the following two files to your laptop:
- northwind-schema.sql
- northwind-data.sql
- northwind schema
In phpMyAdmin, select your username in the lefthand menubar (immediately under
“information schema”). Then go to the Import tab, and under “File to import”, select
“Browse
your computer” and choose your downloaded northwind-schema.sql. The click “Go”. After
a short while a lot of MySQL confirmation messages come up, which you can
ignore.
Now, select your username in the lefthand menubar again, and you should see all the
Northwind tables have been created according to the schema in the file you
submitted.
Open northwind-schema.sql in a text editor on your laptop and browse its
contents.
Now, in phpMyAdmin, click on the names of some of the tables to see their structure, and
see how that structure relates to the SQL commands that create it.
The tables are empty of data so let’s put some in.
Making sure your username in the lefthand menubar is selected, again go to the Import
tab
and this time select and upload northwind-data.sql. And “Go”.
Repeat the above to examine the data in the tables, and again look at the SQL code in
the
data file.
Now use the Designer tool to try and make some sense of the structure. Don’t worry if
you
can’t. But this should show you the difficulty of visualising non-trivial databases.
- You now need to write a query to produce specific outcomes:
- Write a query on the “customers” table to retrieve the names of all customers who
are
company owners in Seattle
- Write a query on the “purchase orders” and “purchase order status” tables to
retrieve
the ids of all purchase orders which have not been approved.
- Write a query on the “purchase orders”, “purchase order details” and
“purchase order status” tables to retrieve the ids of all purchase orders which have
been approved and which have a quantity of between 80 and 120, and order the result
ascending by quantity