0% found this document useful (0 votes)
6 views

1706256595650-T1 Chapter 4 Database

This chapter covers essential database concepts, including data validation techniques, table structures, and the use of queries and reports. Key topics include designing tables for valid data capture, creating forms for user interaction, and utilizing queries to extract specific data. Additionally, it discusses how to create reports with calculations and grouping to present information effectively.

Uploaded by

idrislamees1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

1706256595650-T1 Chapter 4 Database

This chapter covers essential database concepts, including data validation techniques, table structures, and the use of queries and reports. Key topics include designing tables for valid data capture, creating forms for user interaction, and utilizing queries to extract specific data. Additionally, it discusses how to create reports with calculations and grouping to present information effectively.

Uploaded by

idrislamees1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

Computer Application Technology

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.

1.3.3. Restricting the possible values


Creating a validation rule
• A validation rule lists the condition(s) that the data
in a specific field must meet to be accepted as
valid data.
• Validation text can be used together with a
validation rule — this is the message that must be
displayed if the data entered does not meet the
condition(s) in the validation rule.
• The table below contains examples of different
validation rules for different data types, as well as
possible error messages that you can use as the
validation text.

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:

• Method 2: Select the values from another table in


the database.
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.
o Choose I want the lookup field to get the
values from another table or query, then click
on Next.
o Choose the name of the table in which the
values are stored.
o Choose the field with the values that must
appear in the selection list.
o You can choose to display the values in
ascending or descending order.
o Complete the remaining options of the
Lookup Wizard.
• The information in the Lookup tab of the Field
Properties section will be filled in by the Lookup
Wizard. If you want to change the values in the
selection list, you can just change them in the table

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

• Labels contain text which is constant and does not


change from record to record, for example
headings and captions.

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.

4.2. Calculations based on all the records


• Calculations can be placed in the Report Header
or the Report Footer.
• The following functions are commonly used to
create summaries:

• To use these functions, insert a Text Box in the


section where the summary must be displayed.
• Type in the function or formula that you want.

11
• A corresponding Label is automatically added to
the left of an inserted Text Box, and this should be
used for an appropriate description.

4.3. Reports with grouping


• You can make a report easier to read by using
grouping.
• Study the following two extracts from reports. Just
because the participants from Astra HS have been
grouped according to the category, one
immediately gets a clearer picture of the
participants.

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.

o Choose the field on which the records must


be grouped — e.g. Category. A group
header will appear in the report design, but
without any fields in it.
o Move the Text Box containing the relevant
field name from the Detail section to the
newly created Group Header section
o Move the corresponding Label to the left side
in the Page Header section.

o It is usually necessary to customize the layout


of the report to improve the spacing and
readability.
o If sorting was done on any of the fields, you
have to ensure that the Group on instruction
appears at the top in the Group, Sort, and
Total pane. Click on the Move up arrow in

16
the Group on instruction until it appears at
the top.

5. Calculated fields in tables and queries


• We use queries to extract records from a database
table that meet certain specified criteria.
• Apart from using the existing fields, we can also
create in a query - temporary fields which can
contain calculations.
5.1. Calculations with numbers
• Consider the following extract from a database
table Plants:

• By using a query, we can display the fields


GeneralName, PurchasePrice and SellingPrice of
all the records. We can then create in the query an
additional field (to be called Profit) to calculate the
profit on each plant.
• In the design view the query looks like this:

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:

• Functions can also be used in calculations. Here


are two mathematical functions that change the
stored value of a calculated field, not just the way
the value is 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:

• Examine the following new calculated fields that


use these date fields, and that may appear in a
query based on the table Animals:
NumDays: [Date_Adopted] — [Date_Rescued]
• The calculation determines the number of days
between the two dates (later date —earlier date).
The data type of the new field will be Number.
NumMonths: ([Date_Adopted] —
[Date_Rescued])/365*12
• The calculation determines the number of months
between the two dates.
• Note —because not all the months contain the
same number of days, the number of years is
calculated first, and then multiplied by 12.

19
• Date functions can also be used to manipulate
Date/Time fields.

5.3. Calculations with aggregate functions


• In the VisualArts database there are many records
for each school. Each record indicates an amount
for an artwork.
• You can create a query to add up the amounts for
each school, and display the total amount per
school.

• This is done by using an aggregate function in a


query. You use the Sum function to add (group

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.

o Run the query.


• You can also select other functions besides Sum,
for example Avg; Min; Max and Count.
• To determine the number of records in each group,
you can create a query and include the same field
twice in the query. For example, if you want to
calculate the number of artworks in each category,
the query in Design View will contain two instances
of the Category field. For the first instance, the
Group By option is selected, and for the second

21
Count option. The result of the query will look like
this:

6. Calculated fields in reports


6.1. Calculations for each record
• The following is an extract of the report List of
Items in the database SchoolShop:

• Suppose the shop manager wants to know the


total value of each item in stock. To display this
information, we will need an additional field for
each item in the report. This additional field will
contain the result of the calculation InStock *
SeIlingPrice.
• In a case like this, the calculated field is added in
Design View, in the Detail section of an existing
report. A label containing the column heading for
the new field should be added in the Page Header
section.

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.

6.2. Calculations on groups of records


• Calculations can also be done per group and the
functions for this are placed in the Group Footer or
Group Header.
• Let's use the table Entries in the database
VisualArts as an example.

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:

• Now determine the number of learners in each


category as follows:
• Because a group's Footer does not display by
default, you must first display it before you can
enter any calculations in it.
o Work in the Group, Sort, and Total panel.

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

You might also like