Svy2001 Prac1
Svy2001 Prac1
Aim: To provide you with a basic introduction to the ACCESS database system. The practical
session will also involve the creation of the initial set of database tables required to complete the
two assessed ACCESS practicals latter in the module. In this practical session we will cover:
1. The application that you will develop a full database system for.
2. How to start ACCESS.
3. How to create initial tables in ACCESS for data entry.
4. How to load application data into ACCESS tables.
5. Introduce how to create relationships between tables in ACCESS.
Over the next 4 practical sessions you will build a complete ACCESS relational database
application. This will involve you undertaking all database creation, data entry, editing and then
finally analysis of your database in the form of queries and reports. Associated with the 4
practicals are 2 assessed pieces of work that will evaluate your ability to develop and populate a
relational database application and also you ability to perform queries and derive reports from
your database.
The application that you need to develop a database for relates to two surveying companies –
BBS (Big Brother Survey) and PRM (Poor Relation Mapping). The scenario we are working
under is that BBS has recently purchased PRM to expand its portfolio. The directors of BBS as
part of the purchase of PRM wish to develop a fully integrated database of the surveying
contracts that have been carried out by both companies in order to try to optimize the
performance of the new merged company in the future. It is your task to build this integrated
database. Initial information and data is provided for you in the form of a series of flat files. For
the purposes of today’s practical you will need to obtain and download to a sensible folder in
your workspace the following files:
SVY2001_staff_grp.xls
SVY2001_staff_instru.xls
These can be obtained from the module web-page at the links associated with Practical 1.
Remember that module web-page is username (SVY2001_students) and password (relational)
protected. If you have not already booked marked the web-page its URL is:
http://www.staff.ncl.ac.uk/s.l.barr/SVY2001/SVY2001.html
2. Starting ACCESS
Microsoft ACCESS should be available from any networked personal computer on the
University campus. To start ACCESS select Start → All programs → Microsoft Office →
Microsoft ACCESS 2007. After a short delay the ACCESS start-up window should similar to
below:
Select the New Blank Database option and in the entry box at the bottom of the dialog box that
appears enter the name of your new database – call this survey.mdb. Make sure that you create
the database in a sensible place (i.e., a folder on your H drive so that you can access it from any
University cluster machine) and select Create. You should be presented with the following
window:
Also an ACCESS database file will be written to the folder you specified with the name you
entered. If you check the practical folder using the file-manager you should see a database icon
similar to below:
IMPORTANT – Whatever you do not delete this database file. You will lose all of the
practical work you have performed.
In order to build your database application you will need to create a series of initial tables. There
are a number of different ways that a database table can be created. However, we will limit
ourselves initially to creating tables manually. First select the Create tab and then select the
Table option. You should be presented with a new table as shown below:
The first table we will build is the instrument table for our surveying database. This type of table
is ideal to create using interactive methods as it contains relatively few records (rows) and
related fields (columns). In particular the table we will create, in standard notation, is as follows:
Our instrument table – which we will call tblInstrument – will contain 5 entries (rows/records)
of different type of surveying instrument. In particular, the table we will create will be:
To start with we need to specify the fields of our new table. The first one we need to do is the
InstrumentID. To do this enter InstrumentID in the field-name column by selecting the
Rename option shown below:
Also make sure that you set the Data Type to Text. You should also note that this is the table’s
primary key. Now select the View icon and select Design View option. You will be prompted to
save the table, do this and call it tblInstrument. The resulting Design View should look as
below:
Now we need to enter the remaining fields (attribute types) for this table. In the next row of the
table entry, enter the next field name as Type. You should also set its Data-Type to Text and
enter useful descriptive information in the Description column. Repeat this process for Model
and Supplier fields (attributes). Your table composition at this stage should look like:
The next few fields (attributes) require a different Data Type than Text. In order to select a
different Data Type for a field (attribute), you need to press the left mouse button in the Data
Type field and then select the required Data Type from the drop down menu. This is shown for
the remaining three fields (attributes) of our instrument table below:
Using the example displayed above, complete the creation of our instrument table for the
remaining three fields (attributes) – Cost, Accuracy and Service. Once you have done this you
can save the table using either the save icon or by selecting the table tab and Save.
Having created the structure of our instrument table for our database, the next stage involves
entering data into this. This is easily achieved in an interactive manner by selecting the
Datasheet View option from View menu option. Once you select this button the view of the table
changes from creating the structure/attribute types to one that allows you to enter data. This is
shown below with the first instrument description (attributes) entered.
Repeat this and add the rest of the instruments described earlier in the handout and save the table.
For tables that contain a small number of records it is easy to manually enter them to the
database. However, in the case of our application we have 38 members of staff that we wish to
add to a staff table in our database project. In order to do this we will create a staff table and
populate it by importing from an EXCEL spreadsheet. First make sure you have a copy of
SVY2001_staff_grp.xls from the module web-page. Now, we need to load this into ACCESS. To
do this select External Data and then the Excel icon
You will be presented with an import window such as the one below. In this select the file
SVY2001_staff_grp.xls and keep the option Import source data into new table as shown below:
This will result in an Import Spreadsheet Wizard being started. In this select First Row
Contains Column Headings. Work your way through the wizard, ensuring that you make sure
that the following are set as specified below:
The result of this process should be a new table called tblStaff in the Database window. Select
this to make sure that the table has been created correctly. The new table should look like the one
shown below:
In order to take our database further we need to create a table that allows us to link the staff table
and the instrument table, so that we can easily lookup which members of staff are able to operate
particular survey instruments. To do this, we need to create a further table, one that relates the
staff table and the instrument table. In the Database window select Create and then Table save
the new table as tblStaffInstrument. Enter Design View and set this table to have two attributes
StaffID (Data type = number) and InstrumentID (Data type = text). Now you need to set both of
these fields (attributes) to be primary keys. To do this left mouse select the first field while
holding the shift key down and then drag the mouse to the second field. Once both fields
(attributes) are selected you can then select the primary key icon as you did when you created the
first table and then finally save the table. This process is shown below:
Having created the table we now need to create the relationships for this new table and the other
two created earlier. To do this select the Database Tools tab and the Relationships option. In the
window that appears select the three tables and then Add:
The resulting relationship view should look the same as the one shown below (although you may
need to drag-and-drop the table views to get them into the order shown below):
Next we need to build the relationships between the three tables. Our interest is to be able to
define the relationships that allow us to encode (represent) the different survey instruments that
each member of staff is qualified to use. We will use tblStaffInstrument to achieve this.
However, this table only contains staff and instrument IDs – so in order for us to find, for
example, the name of a member of staff we need to build a relationship between the StaffID in
tblStaff and the StaffID in tblStaffInstrument – this relationships will be of the form one-to-
many, in that one StaffID in tblStaff can occur a number of times in tblStaffInstrument. At this
point you may want to consider why a one-to-one relationship would be inappropriate?
In order to actually create the relationship left mouse select StaffID in tblStaff and while the
mouse is still active drag the mouse over to StaffID in tblStaffInstrument. This should result in
an Edit relationship window appearing, in this select Create. The result should be that a
relationship link is created between the two tables, shown below:
Now you need to go through the same procedure for InstrumentID in the table tblInstrument
and tblSatffInstrument. Once you have done this you select Save from the Relationship tab.
The final task in this practical now involves actually loading the StaffID and InstrumentID data
into the table tblStaffInstrument so that we have a record (in terms of IDs) of which member of
staff can use which particular instruments. In order to do this, you need to use the Import option
that we covered earlier in the practical to load the EXCEL spreadsheet SVY2001_staff_instru.xls
into the table tblStaffInstrument. As we have already covered how to do this, this is left as a task
for you to complete. However, when going through the Import wizard you need to select Append
a copy of the records into an existing table In and specify tblStaffInstrument. When you open
the table after this procedure it should look like the one below:
4 Conclusion
Congratulations – you have today completed the preliminary stages of creating your surveying
company database. At this stage we have a number of tables and have built simple relationships.
Make sure you have saved the tables and the relationship layout before existing ACCESS.
In the next practical session we will complete building our database structure and cover issues
such as how to append, delete and add data to tables and relationships.