Acknowledgements
No extract from any source held under copyright by any individual or organisation has been included in this learning pack.
All screen images are copyright of the Microsoft Corporation.
ABOUT THIS SECTION
This section is designed to show you how to perform processes effectively using a database package.
You will learn how to:
• perform routine database processes efficiently and effectively
• perform complex database processes effectively
• save and output data.
By the end of this Study Section you will be able to:
• create tables
• edit and format text
• carry out a variety of database processes
• output data.
This Study Section should take approximately 6–8 hours to complete.
To complete this Study Section you will need access to a computer system with Microsoft
Access installed.
IT/DATABASES/INT 2 3
ABOUT THIS SECTION
How you will be assessed for this section
The assessment for this section is part of the assignment for Outcome 2.
When and where you will be assessed for this section
Assessment for this section is carried out in controlled conditions by arrangement with your tutor.
What you have to achieve for this section
You must complete an assignment to assess your ability to use routine processes for each of three application packages. In addition, one package must be used to complete complex processes.
This section covers the use of both routine and complex database processes.
Opportunities for reassessment for this section
Opportunities for reassessment will be provided where necessary.
4 IT/DATABASES/INT 2
INTRODUCING DATABASES
A database is a collection of related data items, which are linked and structured so that the data can be accessed in a number of ways.
Simple database programs store a single set of data. This is called a flat file database. These types of programs are suitable for holding data for home use. More complex applications, such as those found in businesses, require a more complex database program called a relational database program.
Relational databases separate data into tables which hold data related to a single topic. For example, one table could hold customer details such as names and addresses, while another could hold details of all customers’ orders.
Customer details table
Customer
Number
1021
1022
1023
Customer
Name
White J
Brown F
Green D
Postcode
XY1 3VC
XY3 6FD
XY2 8 GJ
Order details table
Order
Number
10012
10013
10014
10015
Customer
Number
1023
1021
1022
1022
Date
Jan 13th
Jan 17th
Jan 17th
Jan 20th
Value
143.65
259.75
421.00
298.50
As you can see, the data in a table is structured. This is to allow you to interrogate it to get the information you want. The structure is based on records and fields.
IT/DATABASES/INT 2 5
INTRODUCING DATABASES
Let's look again at the customer details table.
Records
V
V
Customer
Number
1021
1022
1023
V
V
Field names
V
Customer
Name
White J
Brown F
Green D
V
V
Postcode
XY1 3VC
XY3 6FD
XY2 8 GJ
V
Fields
A record contains all the information about a single item in a table. In our example a record is the details about a single customer.
A field is a piece of data within a record, for example Customer Number. Each field has a name to identify it.
It is very important to plan a database before creating it. This is done by looking carefully at the data to be stored.
First of all, groups of related information need to be identified. A group of related data will be stored in a table. Tables must be constructed so that each one holds unique data.
Fields that derive their values from calculations on two or more fields can be ignored as they can be calculated by the database software when needed.
Each table should have a primary key. This is a field that gives a unique value for the record. This must be unique, as it will be used to identify the record in some operations.
6 IT/DATABASES/INT 2
INTRODUCING DATABASES
?
1
Look at the Customer and Order details again.
1.
2.
Why do you think that the Customer Number appears in both tables?
What would be the primary key for each table?
Check your answers with the ones given on page 27 at the end of this Study Section.
IT/DATABASES/INT 2 7
INTRODUCING DATABASES
A
1
Microsoft Access is a database program.
This program has facilities to allow you to store information on file so that it can be later opened, searched, amended and printed.
There are many different ways of starting Microsoft Access depending on how the program has been set up. The most straightforward way is to use the Start menu.
Ø
Click on the Start menu.
Ø
Point to Programs.
Ø
Point to Microsoft Office 97 (you might not need to do this step on all computers).
Ø
Point and click on Microsoft Access.
8 IT/DATABASES/INT 2
This dialog box will appear.
Ø
Make sure Open an Existing Database is selected.
Ø
Make sure More Files… is selected.
Ø
Click on OK.
INTRODUCING DATABASES
The Open dialog box appears.
At the top left of this dialog box you will see the words Look In:
On the right of this bring up the drop down list by clicking on the down arrow.
Ø
Search the list for 3½ Floppy (A), then move the pointer over it and click.
3½ Floppy A should now appear in the Look In: box and the Access files that are on the floppy disk will be listed.
Ø
Click once on Sample1 then click the Open button on the right-hand side of the dialog box.
Microsoft Access should now appear in the
Title Bar and Sample1: Database should now appear in the Database window underneath.
IT/DATABASES/INT 2 9
INTRODUCING DATABASES
The database window is where you work with the various elements that make up your database.
Title Bar
Tool Bar
Menu Bar
Minimise
Maximise/Restore
Close
Status Bar
In Access, the data and database objects are stored as a database. Database objects are the various tools available in Access for data management. Tables are an efficient way of organising data; Forms are a front-end tool to view the stored data; Queries, Reports and
Modules offer ways to manipulate data.
When a database is opened these are shown in a box on the database window, as below.
1 0 IT/DATABASES/INT 2
INTRODUCING DATABASES
In more detail, the Access database objects are:
Table Used to store data in rows and columns.
Query
Form
Used to retrieve data from one or more tables which matches criteria you specify. Data can be displayed in any order.
Used to display database records on screen or in print. Screen forms can also be used to input or modify data.
Report
Macro
Used to print records in specified layout. Reports can contain grouped records and can calculate and show totals.
This is a set of instructions to allow Access to perform basic operations automatically.
Module This contains programming code in a language called Visual Basic.
Modules are used to automate more complex functions.
We will look at these in operation throughout this unit. We will start by creating a new table.
A table is a way of storing a collection of data in columns and rows, called fields and records. There are different ways to create a table. One of the easiest ways is to use the
Table Wizard.
Ø
Click on the Tables tab then New.
Ø
Double click on the Table Wizard.
Ø
Click on Customers in the list under
Sample Tables.
This produces a list of typical table entries under Sample Fields. You pick which fields you want from this and add them to the list under Fields in my new table.
We want to create a table with fields to hold a Customer ID number, Company Name,
Address, City, and Phone Number.
The Table Wizard asks you questions about your table and uses the answers to create a blank table for you to add your data to. You can choose features from a variety of common table types, such as business mailing lists, employee records, payments or invoices.
IT/DATABASES/INT 2 1 1
INTRODUCING DATABASES
Let's start by creating a table to hold customer details.
Ø
Select CustomerID from the list in the box under Sample Fields.
Ø
Click the Add icon.
Ø
Repeat for CompanyOrDepartment, BillingAddress, City, and PhoneNumber.
Ø
Click Next.
Next
Sample
Fields
Add icon
Ø
On the next screen, leave the Table title as Customers and select Yes, set a primary key for me then click Next.
Ø
On the final screen, click beside Enter Data Directly into Table, then click Finish.
A blank table is created for you to start typing in your data.
The CustomerID field is an AutoNumber field. This means that it will automatically be assigned a number when you fill in any of the other details in the record. To enter data, simply click in the box where the data is to appear and type.
Ø
Click in the Company/Dep box and type Smith and press Return.
Ø
Type 21 High Street and press Return.
Ø
Type Glasgow and press Return.
Ø
Type 0141555212 and press Return.
There are a couple of things to note:
1.
2.
When you press Return at the end of a record it creates a new blank record.
The phone number looks different – it isn't just the string of numbers you typed in. It has been formatted to match the sample file you copied from. We will see how to change this later.
1 2 IT/DATABASES/INT 2
INTRODUCING DATABASES
So far you have been viewing the table in what Access calls ‘Datasheet View’. This makes it easy to see a lot of the data at once so you can add, delete and edit easily.
Ø
Carry on typing in the records shown below.
You will need to widen some of the columns so you can see the data. Do this by clicking on the column title, press the mouse button down on the right-hand boundary and drag it to the desired width.
Click and drag here
From Datasheet View you can add fields. You click to the right of where you want the field to appear and then insert a new column.
It would be useful to have a named person in each organisation to address letters to. Let's add a column to our table to store a contact name.
Ø
Click in the Phone Number column.
Ø
Click on the Insert menu then click Column.
Ø
Double-click the new column's name, and then type Contact as a name for the column.
IT/DATABASES/INT 2 1 3
INTRODUCING DATABASES
Ø
Add the data shown here into the new column.
Record
1
2
3
4
5
6
7
8
Contact
John Adams
David Watson
Jerry Gower
Susan Proctor
Ann Irvine
J. Thompson
Harold Lindsay
Bob Evans
If you want to customise a field's definition further, for example by changing its data type, you need to use table Design View.
We have already noted that the phone number format doesn't look right. To change this we need to be in Design View.
Design icon
Ø
Click on the Design View icon.
Ø
Click to the left of the PhoneNumber field to select the field.
Click here to select the field
V
At the bottom of the screen a detail box shows the definition information for the field you have selected. For example it shows that the field size is 30 and that there is something called an Input Mask.
1 4 IT/DATABASES/INT 2
INTRODUCING DATABASES
An Input Mask (sometimes called a ‘field template’) is used to control how data is entered in a field. For example, the Input Mask you see for the phone number is used to make sure that all phone number entries contain exactly enough digits to make up a US area code and telephone number, and that only digits can be entered in each blank. We don't need this as it doesn't suit British phone numbers.
Ø
Highlight the text in this field and press the Delete key.
We will create an Input Mask to format our Customer ID. This is just a single number at the moment. We want it to be a 4-digit number.
Ø
Click on the box holding the Data Type for
CustomerID.
Ø
Change it to Number.
Ø
In the detail box at the bottom of the screen type 9999 in the input mask box.
By typing 9999 we force the field to accept no more than four numbers. It also means that no other characters can be entered into this field. For example, letters and punctuation cannot be included.
Ø
Switch back to datasheet view.
Ø
Edit the CustomerID entries and change them all to have 102 before the existing number.
There may well be times when you are only interested in seeing certain information held within your table. Let's say for example you are only interested in seeing the Company
Name and the Contact Name. You can hide the other fields.
Ø
Select the CustomerID field by pointing to the Field Name and clicking the mouse. The whole column will be highlighted.
Ø
Open the Format menu and select the Hide Columns option.
You are returned to the table, but notice that the CustomerID field is no longer shown.
Ø
Use the same procedure to hide all the other fields except CompanyOrDepartment and
Contact.
IT/DATABASES/INT 2 1 5
INTRODUCING DATABASES
The columns are not deleted – only hidden. To return the columns to view.
Ø
Open the Format menu and choose the Unhide Columns option.
Ø
Check all the fields by clicking in the check boxes to the left of the field title.
Ø
Click on the Close button.
The columns will now be shown.
Every time you create a new table Access uses Arial size 10 as a default. You can choose a different font or size or you can add character formats such as bold to alter the way your table looks on the screen and when it prints.
Ø
Select the whole of your table by clicking on the box at the top left-hand corner of the table, next to the first column title.
The whole table will be highlighted.
Ø
Open the Format menu and select the Font option.
Ø
Use the scroll arrows to move through the list of available fonts until you see the font called Comic Sans MS. Select this by clicking on it.
Ø
Select 12 for the size.
Ø
Click OK.
If you cannot see all of the information in the fields because we have increased the size of the font, you should widen the columns affected.
Working in Datasheet View, it is easy to edit data. All you have to do is double click on the word to be changed, in order to select it and type the new value. To select the whole field, carefully move the pointer to the left side of the cell. The pointer will change to a hollow cross shape. Click once to select the text. Try it out now.
1 6 IT/DATABASES/INT 2
INTRODUCING DATABASES
Ø
Double click on the word Farrow in the cell containing the address for Carters.
Ø
Change this word to Fairview.
There are various ways you can print a table in Access. For the time being we will concentrate on printing from the Datasheet View that you are in just now.
It is a good idea first to see how the records will look on the page before you print them.
This is called a preview. To enter Print Preview do one of the following:
Ø
Click on the Print Preview button in the Toolbar.
OR
Ø
Open the File menu and select the Print Preview option. The preview screen will open as shown below.
Ø
Move the mouse pointer on to the preview and watch how it changes to a magnifying glass with a plus sign in it.
Ø
Click the mouse once to zoom in on the preview. Note that the magnifying glass now has a minus sign in it.
Ø
Click the mouse once again to zoom out to the original size of the preview.
You can print from this view by clicking on the Print button.
Ø
Do this now and then close Print Preview by clicking on the Close button.
You are now back in Datasheet View.
Note that there is also a Print button available in Datasheet View. You could have simply clicked on that to print your table. However, it is always a good idea to preview your table before printing.
IT/DATABASES/INT 2 1 7
INTRODUCING DATABASES
You can also print the table using menu options – Opening the File menu,
Selecting the Print option and clicking OK in the dialog box.
All three methods will produce the same results. For most processes with
Access you will have a choice of using menus, icons or dialog boxes.
It’s up to you to choose whichever method suits you best.
If data becomes redundant and is no longer needed, the records will be need to be deleted.
Let's imagine that Smiths have gone out of business and their record needs to be removed from our database.
Ø
Point to the Record Selector (grey box to the left of the record) for the Smiths record.
Your mouse pointer will change to a black arrow.
Ø
Click the mouse once to select the whole record.
Ø
Press the Delete key OR click on the Delete Record button.
Access will display the message box shown informing you that you are about to delete one record.
Ø
Click on the Yes button in this box.
The message box also informs you that, once you have deleted a record by clicking the Yes button, you cannot undo that action. The record is gone for good. This means you have to be very careful when deleting records.
There are three ways to close down your table:
ü
Click on the Close button in the top right-hand corner of the table.
OR
ü
Click on the File menu and choose the Close option.
OR
ü
Click on the Control Menu in the top left-hand corner of the table and choose the Close option from the menu that opens.
Ø
Choose one of these methods and close your table.
1 8 IT/DATABASES/INT 2
INTRODUCING DATABASES
A
2
Load up Microsoft Access.
Task 1
Ø
Open the Cars database.
This holds details of all the cars a local garage has for sale.
Make the following changes:
Ø
Change the price of the red Fiat to 8500.
Ø
The Almera has been sold, so delete this record.
Ø
A couple of new cars have come in. Add these details to the database.
Ø
Change the font for all the data to size 12 Times New Roman.
Ø
Widen columns as required.
Ø
Print the data.
Ø
Save and close the table.
Task 2
Ø
Open the School database.
This holds details of the exam scores of a group of students.
Make the following changes:
Ø
Change the English mark for Peter Evans to 87.
Ø
Avril Kerr's name is incorrect. Change it to April Kerr.
Ø
A new student has joined the class. Add her details to the database.
Ø
Change the font for all the data to size 10 Comic Sans MS.
Ø
Alter the width of the columns as required.
Ø
Print the data.
Ø
Save and close the table.
IT/DATABASES/INT 2 1 9
INTRODUCING DATABASES
A
3
For this activity, we will use a file already created for you. This file contains information about holidays and is called Travel.
There are likely to be times when you would like to view the information in your table in a different order than you created it. Once the data is stored, it can be organised using the data in one of the fields in either ascending or descending order.
For example, if you had a table holding details of all the invoices your customers are due to pay, you could view the data in order of date due (soonest first), or by value of the invoice, or alphabetically by customer name.
Sort
Ø
Open up the Travel table.
Ø
Click anywhere within the Destination column.
Ø
Click on the Sort Ascending button in the toolbar.
The records will now be sorted in ascending order. This is a text filed so the records are sorted alphabetically from A to Z
If you had clicked on the Sort Descending button the data would have been sorted in descending order from Z to A.
Returning records to the original order
You don't have to keep the data in this order. To return it to the order it was in before carrying out the sort:
Ø
Open the Records menu and choose the Remove Filter/Sort option.
Now try the following:
Ø
Sort the records in ascending order on the Operator field.
Ø
Print out the table showing the data in this order.
Ø
Return the records to their original order.
2 0 IT/DATABASES/INT 2
INTRODUCING DATABASES
If you were using a large table with hundreds or even thousands of records in it, it would not be practical to scroll through them all to find a particular record. It is much more useful to use the database facilities to locate the record or records you are interested in.
There are many ways in Microsoft Access to find just the data you need, whether you're looking for a particular value, one record, or a group of records.
For example, with the Find dialog box, you can locate specific records or find certain values within fields
With filters, you can view a set of records to work with while you have a form or datasheet displayed.
With queries, you can work with a set of records that meet criteria you specify.
Find
Ø
Click in the Accommodation field of the first record.
Ø
Click on the Find icon, as shown on the right.
Ø
In the Find What box type BB.
Ø
Make sure that Search is set to All and Match is set to Whole Field.
Ø
Click on the Find First button.
Ø
Access will highlight the word in the first record it finds it in.
Ø
Click on the Find Next button.
Ø
Access will then find the next occurrence of BB.
Ø
Click the Find Next button.
Carry on doing this. When no more records match the criteria we are searching for, Access displays a message box informing you of this.
Ø
Click on the OK button in this box.
Ø
Click on the Close button to close the Find box.
The Find command can also be used to find records containing a single word within a field.
Ø
Click within the Destination field of the first record.
Ø
Click on the Find button.
Ø
In the Find What box type in Costa.
Ø
For Match click on the down arrow and select Any Part of Field.
Ø
Click on the Find First button.
IT/DATABASES/INT 2 2 1
INTRODUCING DATABASES
The Destination field in the first record containing the word Costa will be highlighted.
Ø
Keep clicking on the Find Next button to find all the occurrences of Costa.
Ø
When Access displays the message telling you it has finished searching, click on the OK button, and then on the Close button to close the Find box.
Using Find is OK if you just want to see records that meet certain criteria on the screen.
Filters are used to retrieve a subset of records from a table and allow you to temporarily view or edit a subset of records while you're in a form or datasheet.
For example, if you want to print out a subset of records that match particular criteria, you need to see all the matching records on the screen together. To do this, you can use the
Filter by Selection option.
Filter by Selection
To view all records containing Costa in the Destination field:
Ø
Double click in the Destination field of the first record as this field contains the word we are looking for.
Ø
Click on the Filter by Selection button.
The subset of records matching the criteria that you selected is now displayed.
Removing a Filter
To remove the filter and view all the records in the table:
Ø
Click on the Remove Filter button.
Filter by Form
Filter by Form is very similar to Filter by Selection. The difference is that it allows you to use multiple criteria, i.e. criteria in more than one field.
For example, to see all records with HB accommodation for 14 nights:
Ø
Click on the Filter by Form button.
Ø
Click in the Nights field – note that a downward pointing arrow appears in the field.
Ø
Click on this arrow to see a list of all the values held in the field.
Ø
Scroll down the list and click on 14.
Ø
Click in the Accommodation field.
Ø
Click on the down arrow that appears and click on HB.
Ø
Click on the Apply Filter button.
2 2 IT/DATABASES/INT 2
INTRODUCING DATABASES
This is not a mistake – the Apply Filter button is the same button that you also use to remove filters.
A subset of your records matching the criteria you entered will be displayed.
Ø
Click on the Remove Filter button to return all the records.
The most important facility within any database package is probably its ability to search through records in a table to find information matching specific criteria. You can create various types of queries within Access but the most widely used is the Select Query.
Ø
Make sure that you have the Travel database open.
To create a Select Query:
Ø
Click on the Queries tab then click on the New button.
Ø
Make sure that Design View is highlighted and click on the OK button.
Ø
In the dialog box, highlight the Travel table by clicking on it.
Ø
Click on the Add button then click on the Close button.
Click Queries tab
You are now in Query by Design View and the Travel table appears in the top portion.
The bottom part of this screen is called the Query By Example (or QBE) grid.
IT/DATABASES/INT 2 2 3
INTRODUCING DATABASES
Ø
Click in the first blank field in the QBE grid and a downward-pointing arrow will appear.
Ø
Click on this and a list of fields from the Travel table is displayed in a drop down list.
Ø
Click on the Cost field in this list.
Ø
Click in the Criteria box and type in < 200.
Ø
In the second column click on the Field box and choose Destination from the list.
Ø
In the third column choose Accommodation.
Ø
To view the results click on the View button.
There is only one holiday costing less than 200 so only one record is shown as a match to this query. Your results should look like the picture below.
Saving a query
Ø
Open the File menu and choose the Save option.
Ø
In the Save as box type in Under 200.
Ø
Click on the OK button.
Closing a query
To close the query:
Ø
Click on the File menu then on Close.
You will be returned to the database window where you will see that your query is now listed.
Opening a query
To use this query at any time:
Ø
Click on the query name then on Open.
OR
Ø
Double click on the query name.
Editing a query
A query can be opened and used as a basis for a new query. For example, we can use the
Under 200 query as a basis for an Under 300 query.
Ø
Open the Under 200 query.
Ø
Click on the Design View icon.
Ø
Edit the Criteria field to show < 300.
Ø
Click on View to see the results.
Ø
Save the query as Under 300.
2 4 IT/DATABASES/INT 2
INTRODUCING DATABASES
Querying text fields
Let's build a query to show us all the holidays in Malta.
Ø
Click on the Queries tab then click on the New button.
Ø
Make sure that Design View is highlighted and click on the OK button.
Ø
Add the Travel table to the query.
Ø
Click in the first blank field in the QBE grid to get the list of fields from the Travel table.
Ø
Click on the Destination field in this list.
Ø
Click in the Criteria box and type in "Malta".
Ø
Add the Accommodation field.
Ø
Click on the View button to view the results.
Ø
Save the query as Malta and close it.
This is not as complicated as it sounds. All it means is that you can enter more than one criterion. This means you can be very precise about the information you want to see.
To see how this works, let's search out the Travel table for holidays that cost more than
200 but less than 300 and are either in Malta or Luxor.
Ø
Create a new query using the Travel table.
Ø
Add all the fields in the table to the QBE grid, making sure Destination and Cost are the first two fields.
Ø
In the Criteria row under the Destination column enter "Tunisia".
Ø
In the or row under the Destination column enter "Luxor".
Ø
In the Criteria row under the Cost column enter > 200 And < 300.
Ø
Enter the same expression in the or row under the Cost.
Ø
View your query.
Ø
Save the query.
Ø
Close the query.
Now you try. Create queries to list these:
Ø
Holidays for 14 days costing less than 250.
Ø
HB holidays in Costa Dorada for 7 nights with Thomson.
Ø
FB holidays in 4* hotels in either Luxor or Cairo.
IT/DATABASES/INT 2 2 5
2 6 IT/DATABASES/INT 2
SAQ ANSWERS
1.
?
1: Answers
The Customer number appears in both tables so that there is a link between each order and the customer who placed it.
2.
The primary key is the field, or combination of fields, which uniquely identifies each record in a table.
In the customer details tables, both the customer name and postcode number could be the same for more than one customer, e.g. where mother and daughter with the same name and living at the same address are both customers. The Customer
Number will be the only unique field.
In the order details table, only the Order Number will be unique and it should therefore be the primary key.
IT/DATABASES/INT 2 2 7
2 8 IT/DATABASES/INT 2