Вы находитесь на странице: 1из 15

Getting started with

databases
Reference document

Aims and Learning Objectives


Combined with the document Using and designing Access databases (document
number acc-t6), this course is designed to:
• use an existing Access database;
• create an understanding of relational databases;
• design and modify an Access database.

University of Bristol Information Services document acc-r1


Getting started with databases (acc-r1)

Document information
Related documentation
Other related documents are available from the web at:
www.bristol.ac.uk/is/learning/documentation/docs-by-category.html#db

Getting started with databases (October 05)


www.bristol.ac.uk/is/learning/documentation/acc-r1/acc-r1.doc
If you have any comments or queries about this document mail iser-docs@bristol.ac.uk.
This document may be used wholly or in part by the academic community, providing suitable
acknowledgment is made. It may not be used for any commercial or profit-making purpose without
permission. © 2005 University of Bristol. All rights reserved.
Getting started with databases (acc-r1)

Introduction
Access is the University's recommended database product for Windows on PCs. Access
2000 / 2002 (XP) is supported by the Computer Centre. This document provides an
introduction to database concepts and introduces basic relational database design
techniques. Used with the document Using and designing Access databases (document
number acc-t6) it will enable you to:
• explain what a database is;
• recognise and apply different data types to data;
• identify the appropriate software to use;
• design a simple relational database structure.

The two exercises in this document would be done as a practical group exercise after Task
2 in the document Using and designing Access databases (document number acc-t6).

Prerequisites
Before attending the Access course you must be familiar with Windows - if you are not,
please first attend the Information Services course Getting started with PCs (code
CC1GPC). Experience of Word or Excel is desirable.
Getting started with databases (acc-r1)

Contents
Document information
1. What is database?.........................................................................................1
2. Data Protection Act .......................................................................................2
3. Database Jargon ...........................................................................................3
4. What software should I use? .......................................................................3
Word .................................................................................................. 3
Excel .................................................................................................. 3
Access ............................................................................................... 3
Oracle ................................................................................................ 3
EndNote ............................................................................................. 3
SPSS .................................................................................................. 3
5. Designing a database ...................................................................................3
What is a data type? ......................................................................... 3
Exercise 1. Design a cinema table ...................................................................... 3
6. Designing a relational database ..................................................................3
Relationships .................................................................................... 3
Indexes .............................................................................................. 3
The primary key ................................................................................ 3
Exercise 2. Create a library database ................................................................. 3
Getting started with databases (acc-r1)

1. What is database?
Database programs such as Access (sometimes called Relational Database
Management systems or RDBMS) are used to store information, often large amounts
of information. The information held in a database may be, eg:
• Simple names, addresses and telephone numbers - excellent for mail-merging
letters and labels.
• Bookings (eg, courses, conferences, residential).
• Equipment/maintenance records.
• Admissions data (available from the Computer Centre).
• Undergraduate, postgraduate and past student data (current student data
available from the Computer Centre. The Alumni Office can provide past
student data, and the Careers Service can provide employment details of past
students).
• Finance data.
• Staff data.
• Library catalogues (books and periodicals).
• Dictionaries.
• Research data (eg, medical, scientific, engineering, social science).
• Bibliographic/Reference data (using Papyrus - a bibliography management
package).
• Sound/video clips.
• CD-ROM databases.
If you wish to set up a database that contains University administrative data (eg,
Finance, Admissions, Personnel, Student, or Corporate literature) contact Information
Services as they may be able to help you to link into an existing database.

1
Getting started with databases (acc-r1)

2. Data Protection Act


It is important to know that information held on a computer is subject to the Data
Protection Act and that databases containing personal information must be registered
under this Act. The University carries out a 'block registration' of many kinds of
database so your proposed database may already be covered, but if in doubt you
must check. The Act specifies, for instance, to whom the data can and cannot be
disclosed. In brief:
• Data must be kept securely and in a way that cannot be accessed by
unauthorised persons and should be deleted when no longer required.
• Information may be disclosed to the data subject (and only that data about
themselves), members of staff who need that information for their work, and
persons or organisations named in the registration particulars. University staff or
students requesting information must be recognised either by an identity card or
by authorisation from the Personnel Office or Head of Department. Personal
information may not be disclosed to others, except that information may be given
if it does not include individual's names (eg, reports of analysed data).
• Data held may be used for research, statistical, historical, or other specifically
registered purposes (but not for other purposes).
• Students handling personal data must only do so under the supervision and
permission of the member of staff responsible.
• Individuals have a right to apply to see the data held about them and following a
formal application this data must be disclosed.
If in doubt about whether your database is registered and for further information on the
terms of the Data Protection Act see you department's Data Protection Officer or
contact the University's Data Protection Coordinator in the Registrar's Office.
Note Within Access it is possible to set a password to restrict access to databases. If using
Oracle on a multi-user system a password is required to log on. Be careful who can
see the screen and do not leave logged-on databases unattended.

2
Getting started with databases (acc-r1)

3. Database Jargon

Database A collection of information that is related to a particular topic or


purpose.

RDBMS Relational database management system. Software, such as Microsoft


Access, that enables you to organise and analyse data stored in tables
in a database.

Field A category of information such as surname, date of birth etc.

Record A collection of information about one person, thing or event.

Primary key A way of uniquely identifying a record eg, National Insurance number,
student number.

Index A subset of the data sorted in a particular order eg, by surname.

Object An identifiable unit such as a table, form report or control that you can
select and manipulate as a unit.

Table An object that stores data in rows (records) and columns (fields). The
data is usually about a particular subject.

Form An object you can use to enter, change and view records of data. You
can use a form to display records on the screen or in print.

Query An object that asks a question or defines a set of criteria about data
from your tables.

Report An object you can use to print records in a custom layout. You can use
a report to group records and show totals for groups and grand totals
for the entire report.

Macro A list of actions you want the database software to carry out for you.

Validation Ensuring the information entered into a database is correct according to


the database rules eg, dates are entered as 12/12/98 etc.

Integrity Ensuring the information being entered into one table is compatible with
information in related tables and ensuring that information is not
deleted from one table where other tables are dependent upon it.

3
Getting started with databases (acc-r1)

4. What software should I use?


Holding information in a database format does not always mean using a database
package. Within the University there are five different supported packages you could
use:
• Word
• Excel
• Access
• Oracle
• EndNote
• SPSS
Word
Word is a word processing package which provides excellent mail-merge features.
Word can easily produce mail-merge letters and labels. If this is all you want to do
with your data then you may find that a Word table is sufficient. If you decide that you
wish to convert your data to a database package at a later date a table created in
Word can easily be exported into either Excel or Access.
Excel
Excel is a spreadsheet package which can also be used as a flat-file database (that is,
all the data is held in just a single table). Excel is excellent for financial and scientific
data, although more and more people are using a database for these purposes. Excel
is a simple way of holding financial and scientific data - it can be learnt fairly quickly
and setting up a spreadsheet and basic formulae is straightforward. Excel has
excellent charting facilities which, again, are easy to use. The disadvantage to using
Excel is that it can be time-consuming and often difficult to produce reports and mail-
merges (it is not designed to do this). Although people like Excel's ability to perform
calculations easily and produce stylish graphs and charts, they often become
frustrated at the lack of database features available.
It is important to note that the University Finance Office has database templates
(created in Access) available for departmental staff to use for their financial data, but it
does NOT supply spreadsheet templates. This may affect your choice of package.
Access
Access is a relational database management system (RDBMS). It can be used as a
flat-file database (using a single table) or a relational database (using more than one
table linked together). Access database applications can be created for a large
number of database situations including financial and scientific data - with excellent
results. The disadvantage to using Access is that it is a difficult package to learn. It is
a "big" package with many capabilities, some of which require quite a high level of
technical expertise and occasionally programming knowledge. Having said that,
Access comes equipped with wizards that help the novice to create tables, forms,
queries and reports. A complicated relational database design and implementation
may need the advice and help of a technical consultant (eg, Departmental Support
Officer, Computer Centre database consultant).
Note For bibliographical information use a specialised package like EndNote and not
Access.

4
Getting started with databases (acc-r1)

Oracle
Oracle is a very comprehensive relational database management system. It is
recommended if either large datasets or complex data are needed. The standard
query language SQL is used to interact with the database. Oracle is not
recommended for small databases or for users without relational database experience.
The University's large administrative databases run under Oracle (eg, staff, student
and admissions data). Help from the Computer Centre will almost certainly be
necessary to design or use an Oracle database.
EndNote
EndNote is a bibliography management package. EndNote stores references in a
database. It can search the database to locate the references needed for a particular
bibliography and can produce the bibliography in the style required by a particular
publisher, journal editor, or institution. It can also scan the text of an article or thesis
for citations and generate the corresponding bibliography. EndNote is of most benefit
to academic staff and research students. Check the info on:
www.bristol.ac.uk/is/computing/advice/software/swprice2.htm#endnote
Many departments subscribe to a scheme whereby all their department-owned PCs
and Macs may have perpetual copies of EndNote installed at no extra cost. A list of
these is available but please check with your Departmental Computing Support Staff
for the latest situation. If your department does not subscribe to this scheme then
department-owned single-PC perpetual copies may be bought for £140 via
departmental purchase orders sent to Alan Blackman, Alan.Blackman@bristol.ac.uk.
SPSS
SPSS is a suite of products for statistical analysis and data management that enables
analysts and researchers to access, prepare, manage, analyse, and report on data in
order to solve business and research problems throughout the entire analytical
process.
SPSS can either be installed on a Windows PC or run from the Unix machine ISIS.
The price for the new Windows 'single copy licence' is £70 per annum. There is also a
special "departmental site licence" available at £500 per annum. The deal finishes in
November, 2007. Contact George Gooding, George.Gooding@bristol.ac.uk if you
wish to purchase.

5
Getting started with databases (acc-r1)

5. Designing a database
Before you sit at your PC to create a database you need to think about the most
efficient and convenient way to store the information so that it can be retrieved in the
format required. Although a database definition can be changed after it has been
created, it is much easier to get it right to begin with. Points to consider are:
• The names of your database, tables, forms, queries and reports. Like any other
names, they should reflect the information they contain.
• The way in which you wish to store the information. For example, names of
people should have at least three fields - title, initials and last name - to give
maximum flexibility in using the data; similarly, addresses normally require at
least six fields, for building/house name, street, town, county, postcode and
country (if appropriate).
• The number of tables and fields you require and how the tables might be linked.
Try to think of all the information you might want to get out of the database.
• The names of the fields. These may be up to 64 characters in length, but about
15 is a more normal size to avoid repercussions on default forms and reports
etc. You can use A-Z and 0-9 in your field names but are advised to avoid using
spaces, *, ? or other symbols. Use underscores if you wish to separate field
names. Try to choose sensible names which are self-explanatory.
• The design of forms. If the information is being taken from, eg, a paper form, it
is more efficient to design your on-line form so that the information is entered in
the same order as it is read from the paper form.
• The size of the fields. For example, you might choose a field size of 8 for a text
field that stores eight character codes. That way you can't accidentally enter
more than eight characters in the field.
Warning! If you reduce the size of text fields in tables that already contain data, characters that
no longer fit in the field are lost.

• The type of data to be entered, eg text or numbers that won't be used in


calculations; numbers that will be used in calculations, dates, currency etc. This
can help you decide what data types to use for each field.
What is a data type?
The data type of a field is simply the type of information contained within the field. For
example, the following fields would be classed as Text (also known as Character or
Alphanumeric) data types:
NAME, ADDRESS, POSTCODE, TEL NO;
whereas the field name COST would be a number or numeric field.
Note Although TEL NO is made up of numbers, it is still best to keep it as a text field
(otherwise the database package would omit any leading zeros and may try to perform
calculations on the telephone numbers!)

6
Getting started with databases (acc-r1)

Other common data types include:

Date/Time dates and times are available in various formats

Currency a specially formatted number field

Autonumber a numeric value that increments automatically for each record


added

Hyperlink web address

Memo a very large text field

Yes/No logical (Yes/No, True/False, On/Off)

OLE Object allows linking & embedding of graphical objects

If you are uncertain about how to design your database, you can look at the sample
databases which come with Access to give you some ideas. Alternatively, you can
contact the Computer Centre for advice, preferably before you start collecting any data
or transferring data from another package.

7
Getting started with databases (acc-r1)

Exercise 1. Design a cinema table


Decide how to divide and categorise the information in the following advertisement in
order to create a flat file (single table) electronic database.
The advertisement is one that is regularly placed in a local newspaper and to be
accessed on-line.
It may sometimes contain information for areas around Bristol, eg, Weston-super-
Mare.

Cinemas Week commencing 27/06/96


Odeon, Union Street, (0117-929-0882). ALL SEATS BOOKABLE. Price: £3.00
1. MOONLIGHT AND VALENTINO (15) with Jon Bon Jovi, 2.05. 5.05, 8.05
2. HEAVEN'S PRISONERS (15) with Alec Baldwin. 1.20, 3.40, 5.00, 8.30.

Showcase, Avonmeads, St Philip's, Bristol (0117-972-3800). Price: £3.50


Screen 1: LAST OF THE DOGMEN (PG) starring Tom Berenger, 1.45, 4.25,
7.05, 9.55
Screen 2: THE ROCK (15) starring Nicholas Cage, 11.50, 2.30, 5.15, 8.00, Late
show 10.40
Screen 3: HEAVEN'S PRISONERS (15) with Alec Baldwin, 12.05, 2.20, 4.50,
7.10, 9.25
Screen 4: EYE FOR AN EYE (18), 11.50, 2.30, 5.15, 8.00

Watershed, Canon's Road, Bristol (0117-925-3845). ALL SEATS BOOKABLE.


Price: £2.00
1: UNE FEMME FRANçAISE (18), 6.00, 8.30
2: BEAUTIFUL THING (15) with Glen Barry, 6.05, 8.10

Orpheus, Northumberland Drive, Henleaze (0117-962-1644). Price: £2.25.


Kelsey Grammer & Rip Torn in DOWN PERISCOPE (PG) 6.00, 8.30 .

You will need to determine the names, size and types of fields, eg,
Field name Data type Size / format
Surname Text 25
DOB Date Short date
and
time

8
Getting started with databases (acc-r1)

6. Designing a relational database


Once you have completed the exercise 'Design a cinema table' you can see that a flat-
file (single table) database involves considerable duplication of information. Typing in
repeated information is time-consuming and increases the chance of errors in the
database. It may also involve complex searching through several fields rather than
just one and prove very inefficient for the user. Fortunately a relational database
design can avoid the need for duplicating information and is much more efficient in its
use. A relational database consists of one or more tables. When designing a
relational database you need to learn how to decide what data goes in what tables.
The best way to set about creating a relational database is to create a model on paper
which will act as a framework. Remember the phrase 'rubbish in - rubbish out' - the
database software cannot turn a badly thought out approach into a well conceived
one.
To create a relational database:
• decide what subjects are to be covered by the database;
• decide how they are related to each other;
• decide on the characteristics they have;
• derive the database tables from the design;
• start at a very high level - look at what the subject is about rather than the
conclusions you want to find.
Relationships
In a relational database, you can take data from more than one table at the same time
and display it in a form, query or report. If you want Access to automatically relate
data between two tables you must first create a relationship between them. To create
a relationship there must be a common field between the two tables. There are two
types of relationship which can be formed; one-to-many or one-to-one.
One-to-many relationships
The most common relationship is one-to-many where each record in a table can be
associated with many records in another table. So each primary key value can
appear many times in the related table as the foreign key. (The primary key is a
unique value appearing only once in the 'One' table – see ‘The primary key’ on page
3)
The table at the one-end must have a primary key consisting of one or more fields.
The table at the many-end must have the primary key fields of the one-end replicated
in it to create the relationship. A relationship cannot be created unless there is a
primary key set up in the one-end table. An example would be Staff Development
courses. Each course can be uniquely identified by a combination of the course name
plus the date given. This would form the primary key of the 'courses' table and each
course would be listed only once. Say there was another table called 'attendees'
which held details of staff attending the courses. In this table the primary key of the
'courses' table could appear many times (assuming the course is popular!).
A well-designed relational database aims to eliminate duplication of information. For
example, the cinema database could be held in 3 tables linked by one-to-many
relationships (the many-end of the relationship is shown by the 'infinity' sign).

9
Getting started with databases (acc-r1)

Figure 1 - cinema relationships

One-to-one relationships
In a one-to-one relationship, each record in the primary table can be associated with
only one record in the related table. In this case the related fields must be the primary
keys of both tables. This type of relationship has more limited use. One example
would be Personnel records. This information could be split into two tables, linked by
the staff number. Information contained in one table could be on open access to all
staff whereas the other table may contain confidential information which could only be
accessed by Personnel staff.
It is best to set up any relationships before creating forms, queries or reports so that
the relationships are automatically built into forms and queries created thereafter.
Indexes
Databases use indexes in tables as you would use an index to a book: to find data, it
looks up the location of the data in the index. Adding indexes to fields within your
database which frequently have a condition set on them speed up searches and
queries but may cause delays when making changes to data. This is because
databases must update indexes in a table each time a record is added or changed. It
is only necessary to create indexes if you have a large database and you find that
performance time on queries is slow. With most databases, it is possible to create
multiple field indexes (eg, Surname plus Forenames).
The primary key
The primary key is an important aspect of a relational database. The primary key is
an index where no duplicates and no blank fields are allowed, ie it must be unique to a
particular record. Surnames or course codes could not be primary key fields as it is
likely that there will be several Smiths or students on the same course in the database.
Good primary key fields are student numbers, order numbers etc.
The primary key doesn't have to be a single field. It can be formed from several fields
whose values together uniquely identify a single record. There can be only one
primary key index per table. The primary key is particularly important when creating
relationships between tables.

10
Getting started with databases (acc-r1)

Exercise 2. Create a library database


Draw a relational design for a simple library database, including
books and borrowers, where:
• a person may borrow more than one book;
• the library may have more than one copy of a book.
You need to know:
• who (including contact details) has which books on loan;
• the date borrowed, due back and returned;
• the fines due.

You may use as many tables as you like. Plot out the relationships as in the cinema
diagram on page 3.
Hint:
You will need at least three tables but for efficiency, yet still keeping the design fairly
simple, you could use five.

11

Вам также может понравиться