1706256595650-T1 Chapter 4 Database
1706256595650-T1 Chapter 4 Database
Chapter 3: Database
Naziya Patel
Grade 12
Term 1
At the end of this chapter, you should know the following:
• Reinforce content, concepts and skills from Grade 11
• Data validation techniques
• Queries using and, or, not, wildcards(*), IS Null operator
• Design reports – grouped
• Group headers and footers
1. Tables
• In a database all the data is stored in tables.
o A table consists of related records.
o Each record contains fields which store facts
about the entity for which the table was
designed.
o The fields can contain different data types
(e.g. Short Text, Long Text, Number,
AutoNumber, Currency, Date/Time,
Attachment and Yes/No).
• Visually, tables consist of rows and columns where
every record is displayed in a row and every field
is displayed in a column.
1.1. Extract information quickly from a table
• Information can be retrieved quickly from a table
by the following:
o making use of Filters
o sorting the data
o using the Totals command.
2
1.2. Change the display format of data
• The format in which data is displayed in a table
can be changed.
• Work in Design View and use the Format field
property in the Field Properties section to change
the display format of dates, text fields and
numbers.
3
1.3. Designing for valid data capture
• Valid data means the data is acceptable in terms
of permissible values, or the limits within which it
occurs.
1.3.1. Creating an input mask
• An Input Mask is a field property which can be set
for a specific field in Design View. It is a code
made up of a combination of letters, digits and
symbols, and is used to enforce the entering of
data in a specific format.
• You will receive a table of input mask characters
with your tests/examinations.
4
1.3.2. Giving a default value
• The default value is a value which is automatically
allocated to a field in a new record.
5
Limiting values with a drop-down list
• Another way to ensure the validity of data, is to
create a Combo Box or a List Box so that the user
can choose a value from a list.
• A Lookup Wizard is used to create a list of values.
The Lookup Wizard is activated in the Data Type
column of a field.
• Method 1: Type in the values for the selection list
yourself.
o Display the table in Design View.
o Click in the Data Type column next to the field
you want to change to a list.
o Select Lookup Wizard... from the list. The
Lookup Wizard will activate automatically.
6
o Choose I will type in the values that I want,
then click on Next.
o Enter the values you want in the list. Click on
Next.
o The name of the field appears automatically
as the Label for the selection list.
o Accept this name and click on Finish.
• You will be able to see the values you entered in
the Lookup tab of the Field Properties section, and
you can also change these values here. if
necessary. For example:
7
on which the list is based (and of course save the
table again).
• In the Lookup tab in the Field Properties section,
you can choose to display the selection list as a
Combo Box or as a List Box. This is only important if
you plan to create a form. All the values of a List
Box will be visible on the form, whereas the values
of a Combo Box will appear only when you click on
the arrow.
2. Forms
• Forms are objects that provide a user-friendly
interface to view, add or change records in a
table. Usually only one record is shown at a time
on a form.
• When you design a form, arrange the Labels and
Text Boxes in which the data appears in a way that
makes the form easy to read.
• Controls such as Combo Boxes and List Boxes that
were set up during the design of the table will
automatically appear on the form, and all field
properties that were set during the design of the
table will automatically be 'carried over to the
form.
3. Queries
• A variety of operators are used to formulate
criteria in Access. These operators include >, <,
>=, <=, =, <>. AND. OR and NOT.
8
• Please note:
o Wildcard characters: These characters are
usually used in text fields. They are useful
when you only know a part of the text you
are looking for (first part, last part, or some
part in-between). The Like operator is often
used with wildcard characters. The ‘?’
represents a single character. Therefore ‘??’
9
would represent any two characters. The ‘*’
represents any number of characters (no
characters, one character, or more).
o The criterion Between 10 AND 50 includes
both the minimum (10) and the maximum (50)
values in the result. This works slightly
differently in text fields: For the criterion
Between "O" AND "T" only values starting
with the letters O to S will be included.
o The criteria for text values are not case-
sensitive. For example, the criteria Like
"LOVE", Like "love" and Like "Love" will all
return the same records.
4. Reports
• We can use reports to present information from a
database in an easily readable format.
• The Report Wizard makes the creation of a report
easy. We can then work in Design or Layout View
to make the report more readable or to improve
the appearance.
• A report can be based on a table or on a query.
4.1. A basic report in Design View
10
• In the Detail section, Text Boxes are used to display
data which occurs in the fields of specific records.
• Functions to display the date and page number are
inserted in the Page Footer automatically when
you make use of the Report Wizard.
11
• A corresponding Label is automatically added to
the left of an inserted Text Box, and this should be
used for an appropriate description.
12
4.4. Grouping while creating a new report
• While you create a report using the Report
Wizard, you can select the way in which the
report's records should be grouped.
• Select the field/s according to which the grouping
must be done and you will see that the levels are
indicated on the right side.
13
• You will notice in the Design View of the report that
an additional header section has been created-in
this case the Category Header.
14
4.5. Grouping of an existing report
• If you did not know that grouping had to be done in
a report. or you simply forgot about the grouping,
you can still perform grouping on an existing
report as follows:
o Locate the Group. Sort, and Total pane at
the bottom of the report in Design View. (If it
is not visible, right-click in the grey section
under the Report Footer and select Sorting
and Grouping.)
15
o Click on Add a group.
o Click on the drop-down arrow in the option
Group on.
16
the Group on instruction until it appears at
the top.
17
• Note:
o If you right-click in Design View on a numeric
field and choose Properties, you can specify
the format of the field. As with Excel. this
format will determine how the value is
displayed, but it will not change the stored
value.
o If you enter the name of an existing field
differently to the way it appears in the
underlying table (e.g. if you make a spelling
or a spacing mistake in the field name), the
following dialog box will be displayed:
18
5.2. Calculations with dates
• We can do calculations on date fields to supply
additional information in a report.
• The table Animals in the database
AnimalRescueCentre contains two Date/Time
fields called Date_Rescued and Date_Adopted.
The following is an extract from this table:
19
• Date functions can also be used to manipulate
Date/Time fields.
20
together) the prices for each school, and to
calculate their sum.
• When the query is created, two fields must be
selected:
o the field according to which the records for
the calculation must be grouped (in the
VisualArts example it is the School field)
o the field to be used in the calculation (the
Price field).
• The following steps can be used:
o Create a query based on the Entries table,
and include the School and Price fields.
o Right-click in Design View on either of the
fields and select the Totals option. A new
row with the name Total appears in the
Design View of the query.
o Keep the Group By option for the School
field, and select the Sum function for the Price
field.
21
Count option. The result of the query will look like
this:
22
• Take note:
• A calculated field is entered in the Detail section as
follows:
o Add a Text Box in the Detail section.
o Delete the Label part. (Click on the Label to
display it as an orange rectangle with
handles, then press <Delete>.)
o Type the formula =[inStock] * [SellingPrice]
in the Text Box.
23
• The teacher wants a report of the learners and the
categories they have entered for. She also wants
to know how many learners there are in each
category.
• First create the basic report, grouping the records
by Category. The Design View of the report should
look something like this:
o Click on More.
o The panel will expand to display as follows:
24
o Click on the drop-down menu item without a
footer section and change the option to with
a footer section. A new Footer section will
now appear below the Detail section in the
report design, with the heading Category
Footer.
• A Text Box can now be added to the Footer
section, and the required function =COUNT(*)
entered in it. Do not forget to edit the
accompanying label with a suitable description.
6.3. Tips for planning and creating a report:
• Before you start to create a report, you need to ask
yourself certain questions in order to plan the
report properly:
o Does the report need to include all the
records from the table or only some of the
records, e.g. just the grade 10 learners'
records?
If only some of the records need to be
included. a query must first be created to
extract the required fields of those records
only. e.g. the grade 10 learners. The report is
then based on this query and not on the table
(which would contain all the records).
Remember that reports do not allow you to
choose which records to display once you
have created the report.
o Where must the calculations go?
If the calculations need to be performed on
or applied to all the records in the report,
then they must be placed in the Report Footer
or the Report Header. If the calculations
25
need to be done per group, then they must
be placed in the relevant Group Header or
Group Footer.
Be on the lookout for wording such as 'for
each' (e.g., for each grade) or `per' (e.g., per
city) as an indication that a calculation in the
relevant Group Footer/Header will be
required, and not in the Report
Footer/Header.
26