Database Development Workbook
Database Development Workbook
DEVELOPMENT
OFFICE 2019
LEARNER WORKBOOK
Adding, modifying and deleting data is known as managing data. Software that
allows you to manage data is called a database management system (DBMS).
Access is a popular DBMS.
How does Access store data in a database? Data is stored in the form of tables
in an Access database. A table is nothing more than a set of rows and columns.
The graphic illustrates how data is stored in a table.
You can open Access through the Start menu on the Taskbar.
Exercise 1
Understand that field content is associated with an appropriate data type like:
text, number, date/time, yes/no
When you enter data in the fields of a table, you must set a data type for each
field. Microsoft Office Access 2019 provides ten different data types. You must
select an appropriate data type for the content of each field.
Memo – this data type is similar to the Text data type but
can be used to store lengthy text containing up to 65,335
characters. This data type is ideal for storing descriptions
and notes.
Number – This data type is used to store numbers, which can be used for calculations.
You can assign this data type to fields that will store numeric values, such as the quantity
and price of items.
Date/Time – This data type is used to store date and time values in different formats,
such as 20-Apr-08 or 04/20/08.
Currency – This data type is used to store numbers in the currency format, such as
$4,560.69. The data stored using this type can be used for calculations.
Yes/No – This data type is used to set Format property to True/False, Yes/No or On/Off,
which are the predefined formats. It also allows you to enter a custom format.
DATABASE DESIGN AND DEVELOPMENT Donna Owen December 2020 4
Understand that fields have associated field properties like: field size, format,
default value
Field Size – This property is used to specify the maximum amount of data that can be
stored in a field. For example, you cannot enter more than five characters in a field if
you specify the field size as 5. This property is applicable only for Text, Number and Auto
Number data types. Be aware that the increasing the field size you will increase the size
of your database and subsequently how fast your computer can search through it.
Format – This property is used to specify the format in which numbers, date/time, and
alphabetic characters are displayed. For example, in the MyContacts table, the
BirthDate field can be displayed as 20-Jun-75 or 06/20/75.
Caption – This property is used to set a name for a field as visible in the Datasheet view.
For example, the Birth Date field can be displayed as Birthday in the Datasheet view if
you specify Birthday in the Caption property of the field. This property is applicable for
Text, Number, Date/Time, Currency and Auto Number data types.
Default Value – This property is used to specify a value that is automatically displayed in
the field when you add a record to a table. For example, in a Publishers table, you can
specify High Growth as the default value for the Publisher Name field if the main
publisher is high Growth. This property is applicable, for Text, Number, Date/Time, and
Currency data types.
In Design View, you can use the upper section, Field Entry, to add or delete fields
and specify the data types of these fields. In the lower section of this view called
Field Properties, you can modify the properties of each field in the table.
Create and name a table and specify fields with their data types like: text,
number, date/time, yes/no
A new Database Table in Datasheet
View will appear.
1. Select the Design View option from the Views icon on the Home
tab on the Toolbar Ribbon. You will be asked to give the table a
name, key in MORTGAGES.
2. Firstly, you will be faced with a field called AutoNumber using a Primary Key.
Right click on the Key Symbol and remove.
3. Using the CAPS LOCK key we will enter the field names in
the Field Name column.
4. We will set the data type to Short Text fields except for
the AGE field which should be a number type and the
MORTGAGE field which should be set to currency.
5. When this has been achieved we will click on the Datasheet View
button on the toolbar.
This is the datasheet view where you can enter your records.
DATABASE DESIGN AND DEVELOPMENT Donna Owen December 2020 6
Set up and use Spell Checker to ensure accuracy in your work
You should always ensure your work is correct. The spell checker tool in Access
will help you check for accuracy but you should also proof read your data entry
as well.
As we will be using UPPERCASE for our text entries ensure that the tick has been
removed, as shown and click OK.
7. Should any of the data be too long to fit in the field width, place the cursor
in the gutter between fields and double click. This will widen the column for
the longest word.
You can add or delete records from a table in Access simply by creating a new
record at the end of the database.
Exercise 4
To delete a record highlight the row for that record and click the delete button
in the Records group of the Home Tab.
You can modify or add data in a record simply by overtyping the data in the
relevant field that you wish to change.
To delete a record simply highlight the record in the left-hand margin of that
record and press the delete key on the keyboard.
Exercise 5
Exercise 6
You will see that no information has been entered in the Membership Number
field.
2. Switch to design view and for the field property of membership number
enter the following in the validation rule box.
>0 And <=40
This means that the number can be greater than 0, but equal to or less than
40. Save the design.
We do not want anybody in the table who joined the club before the year 2000
or after the year 2004.
You only want to accept initial fees between £200.00 and £850.00 and also
would like to edit the validation error message yourself to say Do not accept fees
of this amount.
12. In Design View select the initial fees field, and type in the following rule:
>200 And <850
7. In the validation text box type in the text Do not accept fees of this amount.
8. Enter an invalid amount in a new record and observe the error message,
which should be the one you created.
9. Save the database and close.
When viewing a table in Datasheet view you can sort the records by any chosen
field.
Exercise 8
A primary key is a field that uniquely identifies records in a table. Each value in
the primary key field, such as 1 and 2 is different for every record.
Exercise 9
You have created an index in ascending order of Name in the Results table.
You can add field to database tables that are already created. You would
simply need to open the required database table and add the field.
Exercise 11
To change the width of a column in a table simply click between the two field
headings and drag inward to narrow the column or outwards to widen the
column.
If you have to find a record, based on a specific condition, from a large number
of records in a database, it can be time-consuming. For example, finding a
record with the address ’12 Anne Street’ in a telephone database containing
thousands of records will take a considerable amount of time. In this situation,
you can use the Find tool of Access to locate the record in the table.
To find a record, you must open the table in which the record is to be searched.
In this case, we will find the record in the Results table in the ExamResults
database.
Exercise 12
Exercise 13
In Access, when you use a filter, you view only those records that you want to
see and the rest of them are hidden. This is much like the concept of using a
water filter to filter out dust particles. You can create a filter on a table, using the
Filter by Selection method.
Exercise 14
To create a filter, you must select an occurrence of the value which you want to
use to restrict the view of records. In this case, we want to filter records based on
the Department field. We want to view records of results in the Accounts
Department only.
Once you have viewed the filtered records, you can again view all records by
removing the filter that you added.
1. To remove the filter from the Results table, click the Toggle Filter command
in the Sort & Filter group on the Home tab.
We can apply a filter when viewing a Form too. Take a look at the Form shown
here. You can see at the bottom the indicator that shows that there are ten
records in the database. Next, we will select the field that shows the Type for this
record and apply a filter.
Exercise 15
1. Open the Results Form.
2. Click in the Department field on the word Computer.
3. Select Filter from the toolbar Ribbon.
4. Filter on Computer.
5. There are now only 6 records in the database for Computer.
6. Click Toggle Filter to Remove the filter.
7. Save and Close the database.
As an example, we will use a college tutor database. The college uses a database
containing 2 tables, 1 about students and 1 about their personal tutors. The table for
the tutors uses the tutors initials as a code to identify each tutor. They make sure
that the codes are unique by adding extra letters if necessary, e.g. John Smith has
JS as a unique code, but Pete Brown and Philip Black would be referred to as PBn
and PBk. Each student is given a unique student ID code. In the tables below the
Primary Key fields are in Italics.
There is a relationship between these two tables. Each student has a personal tutor,
so if we put a tutor Initials field in the student table it will identify the personal tutor for
each student.
The Tutor Initials field is the only field that is duplicated. In the Personal Tutor
table, it is the Primary Key field. In the student table it is known as a Foreign Key
field. A Foreign Key field should always be a Primary Key field from another
table.
DATABASE DESIGN AND DEVELOPMENT Donna Owen December 2020 17
Why use the Tutor ID a s a foreign key field in the student table, instead of the
Student ID as a Foreign key in the Tutor table?
Well we know that each tutor has many students, but the students only have one
tutor, therefore the tutor table would have had to have many students ID fields
added to its table, as shown below:
The relationship must always be set up from the ONE end to MANY end.
Remember - copy the Primary Key from the ONE end to the MANY end.
In the above example this means that the Initials of the Personal Tutor will be
listed in each record in the Student table. In the Student table the Student ID
field is still the Primary key. Tutor Initials is known as a foreign key in the student
table, because it is the primary key in a foreign table.
We can use this dialog box to apply ‘Rules’ to the relationships we create. If you
choose ‘Enforce Referential Integrity’ then Access prevents you from making any
changes to the tables that would compromise the integrity of the relationship. It
would, for example, prevent you from deleting records from the primary table
when there are matching records in a related table.
Exercise 16
2. Create two tables containing the information below, one called Personal
Tutor, and one called Student.
Student Table
When setting up the different tables the relating fields in each should have the
same data type and field properties as shown in red.
3. Close and save the tables before entering the data, as the relationship
must be set up before any data is entered.
5. Click the Show Table icon on the toolbar and then double-click the names
of the tables you want to relate, and then close the Show Table dialog box.
6. Arrange the tables so that the Tutor table is on the left and the Student
table is on the Right, and stretch them so that you can see all the fields.
7. Drag the tutor initial field in the tutor table to the tutor initial field in the
student table.
8. The Edit Relationships dialog box is displayed. Check the field names
displayed in the two columns to ensure they are correct.
9. Tick the Enforce Referential Integrity check box. This will ensure that the
user does not enter Tutor Initials in the Student table that do not already
exist in the Tutor table.
Referential Integrity
Rules that you follow to preserve the defined relationships between tables when
you enter or delete records. You cannot delete fields that joint tables as long as
links to another table exist.
The ONE to MANY link is drawn with representing the MANY end.
12. You will now enter the data in the appropriate tables, making sure that you
enter the data in the tutor table first, as nothing can be entered into the
tutor’s initial field in the student table until the details have been entered
into the tutor table.
Tutor Table:
Tutor Initials DO AR KB BE JS
Forename Donna Andy Karen Brenda Joyce
Surname Owen Royle Baker Emett Selby
Department Computing Accounting English Mathematics Music
Delete a Relationship
And now after all that hard work we are going to delete the relationship.
A query is used to extract and analyse data from a database. Data can be
extracted from one table of a database or several tables. A query allows you to
choose the fields and specify the criteria that could refine your search. It is
possible to store a query in a database making it available for use again, if you
have to search for records based on the same criteria.
In Access, you can either use the Design view or the Wizard method to create a
query.
Exercise 17
7. The records will now be sorted in alphabetical order of NAME for properties
of the FLAT type.
8. Close down the query by clicking on the X in the right hand corner of the
query box. You will be asked if you wish to save the query. Save as NAME
ASCENDING FLAT.
9. Save and Close the file.
In this exercise we will create a query that uses two tables to produce a list of
Students with the tutor CJC. We want the list to include the Department for these
students. We will use the Design view for creating the query.
Exercise 18
Add criteria to a query using one or more of the following operator: = (Equal), <>
(Not Equal to), < (Less than), <= (Less than or equal to), > (Greater than), >=
(Greater than or equal to)
Alternatively, you can use the OR logical operator to retrieve records that meet
any one of the specified criteria. For example, if you want to retrieve records of
employees who live in Chicago or New York, you should use the OR logical
operator while specifying the criteria. To use the OR logical operator, you must
specify the alternative criteria in the row labelled OR.
You can use the NOT logical operator to exclude records that match the
specified criterion. For example, if you want to exclude records of employees
who have the Job Title of MD, then you should use the NOT logical operator
while specifying the criteria under the Job Title column. You can do this by
entering MD with the prefix NOT or the symbol <> in the row labelled criteria.
Exercise 20
For example, if you were looking for all customers who were in Purchasing, then
you would use Job Title as Purchasing* - this would find both Purchasing
Managers and Purchasing Representatives. You can also use Purchasing% to
look for Job Titles in Purchasing – this would return the same result. The wildcard
characters * and % match any number of characters, but the character *
cannot be used with the % character in the same expression.
# matches any numerical entry. If you were looking for a range of numbers from
200 to 299 you would use 2##.
Exercise 21
Exercise 22
1. Select the Create tab on the Toolbar Ribbon.
2. Click the icon for Query Design.
3. Add the Membership table and close.
4. Take all the fields down.
5. In the Membership Type column on the criteria row enter F?????
6. Run the query – this will pick up all records for Family.
7. Save the query as Family.
We will use the same database for the next query.
You can modify or remove the criteria already specified for a query. To modify
criteria in a query, open the query in the Design View and select the criteria to
be modified. Then, type in the new criteria over the existing one and press the
Enter key on the keyboard. To remove criteria in a query, again, open the query
in the Design View and select the criteria to be removed. Then, press the Delete
key on the keyboard. After modifying or removing a query, click the Save
button on the Quick Access Toolbar to save the changes made to the query.
Exercise 24
Exercise 25
Along with the existing fields in a query, you can also add new fields to view
additional information. You can also remove a field.
Exercise 26
You might decide that you want to change the order in which the query
presents the columns. You can change the order of the columns by simply
dragging columns from one place to another.
Exercise 27
Exercise 28
When you are working with a query you can also hide fields that are not relevant
at the time. To hide a field just click the tick box, located at the bottom of the
field in the Design View, once so there is no tick showing. To unhide a field, just
click the tick box so the tick is showing again.
You have seen that the Datasheet view of a table is used to enter and display
data. However, sometimes you might find the Datasheet view format difficult to
use. Access has a feature that allows you to create an easier to use format,
called a form.
Exercise 31
To delete a record in form view, scroll through the records until you find the one
you wish to delete. Click on the left side of the record and press the Delete key
on the keyboard.
Exercise 32
1. Open the Exam Results database from your learner drive.
2. Open the Results form.
3. Delete record no 9 for Natalie.
4. Save the form.
5. Save and close the file.
Exercise 33
Exercise 34
Exercise 35
Here are the three main sections that are displayed when a form is opened in
the Design View.
Form Header – the form header section is used to display information such as the
heading or the form or the logo of an organisation. The information provided in
the Form Header appears at the top of the form.
DATABASE DESIGN AND DEVELOPMENT Donna Owen December 2020 30
Form Footer – the form footer section is used to display information such as date
and time at the bottom of the form.
Detail Section – the detail section of the form is used to display the records of a
table.
Exercise 36
When you see a mailing label, an invoice, or a sales summary, you find data
presented in suitable format. These are different examples of a report. Reports
can be created using data from a table or a query in different formats and are
suitable for producing printed output. A report can include selected data from
many tables and queries at once and perform calculations on that data, with
neatly formatted results as the output.
Exercise 37
It is easy to use the Report Wizard to create a report. The wizard, however, does
not give you much freedom to experiment with the appearance of the report. A
simple report created using the Report Wizard might look like what you see in the
graphic above.
Exercise 38
You can group records on any field in a report. For example, in a sales report,
you could group the sales using the month field, so it shows all sales by month.
When grouped, records are shown together under a heading called Group
Header. This heading has the name of the field on which the records are
grouped. Like Group Headers, reports can also have Group Footers. You can
show useful information, such as the sub-total for the grouped records, at the
end of the group in Group Footer.
Exercise 40
We will now see how we can add useful information at the top and bottom of a
report in such a way that the same information is automatically printed on each
page of the report.
Page Header and Footer are the sections of a report that display information at
the top and bottom of a page.
Report Header and Footer are the sections of a report that display information at
the beginning and end of a report.
You would use Report Header when you want to print information only once in
the beginning of a report. Generally, you will use Report Header to print
informaiton such as the title of a report. You would use Report Footer to print
informaiotn such as a summary and grand totals at the end of a report.
You can use Page Header and Footer when you want to print information at the
top and bottom of each page in a report. For example, the headings and fields
can be the page header and the date and page number can be the footer.
We will now amend the Report header and insert the date and page number for
a report.
Exercise 42
You can also choose to export the output of a table or query as a text file, a
spreadsheet or an XML file.
Exercise 43
You can also send your documents to PDF or EPS files instead of printing them.
We have now seen how we can print tables. We can also print reports and
forms. Just like before, you can use the Print Preview option to see how the form
will appear on the printed page.
You can print the results of a query by clicking the Microsoft office button,
moving the mouse to the Print option and then clicking Quick print. If you wish to
make changes to the paper size or the orientation of the page, select Print
preview you can now change the orientation to Landscape and export the file
to PDF.
Exercise 44
Exercise 45