0% found this document useful (0 votes)
2 views28 pages

Databases

Uploaded by

tum chris
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)
2 views28 pages

Databases

Uploaded by

tum chris
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/ 28

DATABASES

Specific Objectives
By the end of the topic the learner should be able to:
1. Define a database
2. explain the concepts of database
3. explain data organization in a database
4. create a database
5. edit a database
6. design a form
7. apply basic concepts of queries
8. create report and labels
9. print queries, forms and reports

INTRODUCTION
In our day to day activities, we are often faced with the need to keep, search for or give a report. i.e. use of tools
such as diaries. Traditionally human beings used to manage data and information manually by using simple
devices. However these methods have a number of weaknesses which include:-
1. Unnecessary duplication of data.
2. Boredom and time wastage especially when searching for a particular item.
3. Misleading reports due to poor data entry and organization.
4. Poor update of records.
However, in the current world electronic database have changed the way data and information is created,
managed and stored in order to address such weaknesses.
DATABASE CONCEPTS
- A database is a collection of structured and related data items organized so as to provide a consistent and
controlled access to the items.
OR
- A database is an organized collection of related data.
Database management
Is the process by which information is organized and stored on a computer in such a way that there is
efficient retrieval, updating and manipulation of the data.
MANUAL FILE SYSTEM
- This is where a file is set up in such a way that it holds information relating to a customer, project or even a
product and also employees’ information in an organization. For example in the hospital a doctor can
create a file and assign a unique number for each patient.
Major problems that arise with respect to Manual databases are:
a. Alteration – the records can be altered and falsified. Crucial documents such as financial records can be
wrongly changed by dishonest employees. Even though this can happen in any database system, it is
minimal due to the required log-in password, which requires only authorized personnel that can make
changes.
b. Data redundancy – it arises in the old filing system as a result of data duplication. New temporary files
are usually created whenever the original one is not available for some transactions which is a waste of
valuable space and other resources.
c. Data security – prevention of unauthorized access of sensitive information is never guaranteed in the
manual system.
d. Absent backup mechanism – backing up or records is not an easy process in the old filing system.
Natural disasters such as floods, earthquakes can destroy vital information.
Others include – destruction of vital information by employees, stealing, carelessness, data isolation and data
inconsistency.
- To create and manage database, they use Database Management System (DBMS) software. The software
facilitates the creation, organization and maintenance of databases. The DBMS lies between the physical
database itself and the users of the system. Examples of database management software include Microsoft
Access (Ms Access), Microsoft SQL Server, Oracle, FoxPro, DbaseIV, Lotus Approach and MySQL.
Database system
A database system consists of four major components:- data, hardware, software and users.

DBMS

Application End user


programs

AGHS COMPUTER STUDIES ©2012 TOPIC: DATABASES NOTES PAGE 1


Data:-
- They are the values physically recorded in the database.
Hardware:-
- It consists of the secondary storage devices like disks, tapes which the database resides, together with
the associated devices, control units and channels.
Users:-
- There are basically three broad categories of users:-
a. Application programmers
b. End users
c. Database Administrator
i. Application programmers
- They are responsible for writing application programs that use the database by using development tools
available with the DBMS such as Visual Basic, which comes with Microsoft Access.
- The application programs operate on the data in all the usual ways: retrieving information, creating new
information, modifying or deleting existing information. All the functions are performed by issuing the
appropriate request to the DBMS.
ii. End users
- They interact with the database from a terminal. One may employ a query language provided as an
integral part of the system, or invoke a user-written application program that accepts commands from the
terminal and in turn issues requests to the DBMS on the end-user’s behalf. The user performs functions
such as retrieval, creation, modification and deletion.
iii. Database administrator
- The database administrator (DBA) is the person who is the overall in charge of the system. He is
responsible for determining the information content of the database, defining authorization checks and
validation procedures, monitoring performance and responding to changes in user requirements and
defining a strategy for backup and recovery.
Database Management software performs the following duties:-
a. Allow the user to add or delete records.
b. Update or modify existing records.
c. Organize data for easy access, retrieval and manipulation of records.
d. Act as an interface between a database and other application programs.
e. Ensure security for the data in the database by safeguarding it against unauthorized access and
corruption (damage).
f. Keep statistics of data items in a database.
g. Ensures data integrity – this is done to make sure that the data complies with the set up standards in
order to ensure its validity and consistency, which is usually done through the use of integrity constraints.
Data integrity is the correctness and internal consistency of data. For example a field may be defined to
accept only numbers less than 10. If one enters 13 instead, will not accept unless it is less than 10 which is
valid.
h. Allows multiple users to access the same data – in relational database, many users can read and
manipulate the same data at the same time in the same database. For example, one user could be
updating the bill paid by a particular customer while the other will be updating the address of the
employees. This saves a lot of time as one does not need to wait for one to finish first.
Advantages of a computerized database
a) Information can be accessed quickly and easily with little probability of it being lost.
b) Related files can be linked together – once one is updated and the related file(s) will also automatically be
updated.
c) Information need not be duplicated: it can be stored only once and accessed in several different ways.
d) It is easy to update or change records and their structure in computerized databases.
e) Data entered can be easily validated, thereby preventing mistakes on entry.
f) It is easy to store backup copies of the database ‘offsite’.
Disadvantages
i. Database operators require training, which may take some time.
ii. It is easy to copy or steal files unless the files are stored and protected carefully.
iii. Computer breakdown can cause files to become inaccessible or corrupted.
Traditional filing methods
- It is an old way of organizing files in which data is stored within a single file or table; unlike the present
relational database systems in which data is split into separate tables each containing different data items
but all are related in some way.
- The traditional file system is almost obsolete but it is still used by many organizations because of:-

AGHS COMPUTER STUDIES ©2012 TOPIC: DATABASES NOTES PAGE 2


a. It is less expensive – does not need experts to maintain.
b. It is easy to manage – there are no programs written that are used in the retrieval of data such as
application programs.
c. Modern database are expensive – for small organizations, it is expensive to purchase and maintain the
new database system as they need experts and qualified database administrators to install and manage
these complex systems. Also Database Management System Software (DBMS) is very expensive for small
organizations.

ENTITY RELATIONSHIP MODELLING


It is a technique used to identify the objects within an organization and how they are related to each other.
Definition of terms
Entity:-
- It is a thing or object of significance, whether real or imagined, about which information needs to be
known or held. It can be an object with a physical existence such as person, car, house etc or it may be an
object with a conceptual existence such as a company, a job, a house
Example:-
- A supplier has to maintain a list of all items that he/she supplies. The list may include:- description, price,
category, product number etc. The entity here is the item about which information needs to be stored.
- Every entity has particular properties or attributes which describes it

Name Product code Price Description


Lotion 2342 120 Body care
Bread 2300 31 Edible
Pen 1200 12 Stationery
Sugar 2390 200 Edible
Attributes
An attribute is any detail that serves to qualify, identify, classify, quantify or express the state of an entity or any
description of a thing of significance.
An attribute could be text, numbers, a picture, a feel, a smell, sound etc as required.

Addres Student AdmN

Name

- The ellipses in the above figure represent the attributes. Student’s address, admission number, name etc
are called attributes.
- Any attribute or set of attributes can be used to uniquely identify a row in a table. Such attributes acts as a
candidate for a Primary key and is referred to as the Candidate Key.
- A candidate key can be chosen as a primary key depending on factors like uniqueness, usage etc. Thus a
primary key is a field or set of fields in a table that uniquely identifies every record.

TYPES OF TABLE RELATIONSHIPS


A relationship is an association among entities. It may associate an entity with itself.
There are three types of table relationships. There are three types of table relationships:

 A one-to-many relationship

Consider an order tracking database that includes a Customers table and an Orders table. A customer can
place any number of orders. It follows that for any customer represented in the Customers table, there can be
many orders represented in the Orders table. The relationship between the Customers table and the Orders
table is, therefore, a one-to-many relationship.

To represent a one-to-many relationship in your database design, take the primary key on the "one" side of
the relationship and add it as an additional field or fields to the table on the "many" side of the relationship.
In this case, for example, you add a new field — the ID field from the Customers table — to the Orders table
and name it Customer ID. Access can then use the Customer ID number in the Orders table to locate the
correct customer for each order.

AGHS COMPUTER STUDIES ©2012 TOPIC: DATABASES NOTES PAGE 3


 A many-to-many relationship

Consider the relationship between a Products table and an Orders table. A single order can include more
than one product. On the other hand, a single product can appear on many orders. Therefore, for each record
in the Orders table, there can be many records in the Products table. In addition, for each record in the
Products table, there can be many records in the Orders table. This type of relationship is called a many-to-
many relationship because, for any product, there can be many orders and, for any order, there can be many
products. Note that to detect existing many-to-many relationships between your tables, it is important that
you consider both sides of the relationship.

To represent a many-to-many relationship, you must create a third table, often called a junction table, that
breaks down the many-to-many relationship into two one-to-many relationships. You insert the primary key
from each of the two tables into the third table. As a result, the third table records each occurrence, or
instance, of the relationship. For example, the Orders table and the Products table have a many-to-many
relationship that is defined by creating two one-to-many relationships to the Order Details table. One order
can have many products, and each product can appear on many orders.

 A one-to-one relationship

In a one-to-one relationship, each record in the first table can have only one matching record in the second
table, and each record in the second table can have only one matching record in the first table. This type of
relationship is not common because, most often, the information related in this way is stored in the same
table. You might use a one-to-one relationship to divide a table with many fields, to isolate part of a table for
security reasons, or to split a table that would otherwise have too many fields. When you do identify such a
relationship, both tables must share a common field.

DATABASE MODEL
It is a specific method for describing the structure and processing within a database. The main database models
include:-
i. Flat file
ii. Hierarchical
iii. Network
iv. Relational
NB:
The current database model trend is towards new models namely object relational and object oriented models.

 Flat File
The database holds only one set of data and is not any different from the manual files. For example, the teacher’s
assessment report may consist of performance cards for every student in a class. Another example is the cards
used in a library books catalogue. The cards are arranged sequentially for easy access e.g. alphabetically using
book’s title or by authors’ names. It is very hard to establish relationship between the items other than the
sequence in which they are stored.
Name Performance
Admission number 7680
Total marks 560
Number of subjects 8
Average 70
Position 2

AGHS COMPUTER STUDIES ©2012 TOPIC: DATABASES NOTES PAGE 4


Limitations
- Locating a record is very tedious – if one has to locate a particular data item, the search starts at the
beginning and the subsequent items are checked until the required item is found.
- If data has to be inserted, the whole file has to be read and rewritten.
- Any changes in the database has to be updated which is also tedious.
 Hierarchical Model
- The data items are arranged in a hierarchical (tree) form as shown in the diagram below. To access level
two data items, one has to access level 1 data items.
- A level 1 item is called the root component. A specific single path leads to each item at lower levels. The
model represents a one-to-many relationship.

Root (main data item)


Path

Level 1 (data item)

Limitation
- It is not possible to insert a new level in the table without altering the structure. This makes it impossible
not to support many-to-many relationship.

 Network Model
- These types of organization, links are used to express the relationship between different data items,
forming a network of data items. Access to one item can be through multiple paths and from any item. This
type of model brings about many-to-many relationship.

Company 1 Company 2 Company 3

Item 1 Item 2 Item 3 Item 4


- For one to know which company(s) is selling a particular item or which particular item the vendor sells, it
is completely dependent on the pointer to map out the relationship.
Limitation
- Incase of large volumes of data, it is very difficult to locate the item because it will increase the
complexity of the search, as it uses pointers.
 Relational Database Model
- It is the most common type of model used on minicomputers and microcomputers. In this type of
organization, related data items are stored together in structures called relations or tables. Relationship
can be created between tables such that a record(s) from one table relates to another or other records in
another table.
- The tables below shows customers and orders table that are related by two fields; the CustomerID
(Primary Key) and CustomerID (Foreign Key). In this case, the orders table shows that one customer with
number 450 has made several orders.

CustomerID Name Tel. No.


2130 Mercy Koech 02389898
7890 Peter Karimi 08899489
8789 Bat Korir 09565656
7899 Mary Ngure 89984888

CustomerID Order No. Date Amount (Ksh)


2130 5654 7/3/2009 89000
8789 56 8/4/2009 78800
8789 67 6/8/2009 67000
8789 874 5/8/2009 77880
 Object Oriented Models
- The next generation of database model will look at records as objects that are independent and how they
relate with the other objects in a database. Such databases are still at developmental stages. However
many databases today combine object and relational concepts to come up with object relation models.

AGHS COMPUTER STUDIES ©2012 TOPIC: DATABASES NOTES PAGE 5


DATA INTEGRITY
- It is meant to ensure correctness and completeness of the data in the database. When the contents of the
database are modified, the integrity of the database is lost. To maintain consistency of data, integrity
constraints are imposed. They restrict and validate the data values that are added or updated in the
database.
Some of the constraints include:-
a. Validity integrity
b. Entity integrity
c. Referential integrity

Validity integrity
- It checks if the data entered in the database matches the column data type. For example if a column NAME
is defined to be of character type and one tries to enter numeric value, then it will display an error
message.
- A DBMS checks this rule each time an add or update attempt is made on the column.
Entity integrity
- An entity refers to any data recorded in the database. The primary key is used as an identifier of the row.
- This does not allow duplication of data as no component of the primary key is allowed to accept a NULL
(blank or empty) value. For example, consider a table having student admission number and name,
where AdmNo is the primary key. Numbers cannot be duplicated.
AdmNo Name
7890 Ann
7870 Grace
7909 Jane
8790 Beatrice

Referential integrity
- It establishes a parent-child relationship between tables. A foreign key is defined on a column to declare
this constraint.
Example:-
STUDENT TABLE SCHOOL DETAILS TABLE

Adm.No Name Adm.No Class Hostel


001 Jane 001 One Venus Chania
002 Loise 002 One Pluto Kareri
003 Agnes 003 One Pangani
004 Beatrice 004 Jupiter Jogoo
One Mars
- The admission number (AdmNo) of the parent table is the
primary key and the AdmNo of the child table is the foreign key.
- When a new row is inserted into the child table, its foreign key value must match with one of the primary
key values of the parent table. The same rule is applied for updating and deleting rows.
NB:-
- Any changes in the parent table should reflect in the child table.

FEATURES OF A DATABASE MANAGEMENT SOFTWARE


Most database software contains a collection of features that provides the user with a means to manipulate data in
a database. The features include:-
a. Tables
b. Queries
c. Form interface
d. Report generators
e. Macros
f. Modules
g. Pages
Tables / file structure.
- It is a database structure that is used to hold related data records. Tables are organized in rows and
columns with each row representing a record while each column represents common fields in each
record.
- The table below represents three records and each record is made up of four fields.

AGHS COMPUTER STUDIES ©2012 TOPIC: DATABASES NOTES PAGE 6


FIRST NAME SECOND NAME LAST NAME CLASS
Jane Njeri Njuguna Form one Pluto
Grace Wanjiru Mburu Form one Mars
Nancy Wangeci Mungiria Form two Pluto
Queries
- A query is a statement used to extract, change, analyze or request for specific data from one or more
tables. A query can select and define a group of records that fulfill a certain condition. You can use
queries before printing a report so that only the desired data is printed. You can also use a query with
forms so that only certain records that meet the desired criteria appear onscreen. You can also use
queries within procedures to change, add, or delete database records.
- For example, the school bursar may wish to display all students who have a fees balance of more than
Ksh.5000. he can use a query to extract the required records.
- The query statements are written using a special language called Structured Query Language (SQL). The
user creates a query by writing structure query language statements such as:-
Select AdmNo, Name, Fees balance
From
FeesTable
Where
FeesBalance = “>5000”
Forms / Input screen
- A form is a graphical interface that resembles an ordinary paper form. Data-entry forms help users get
information into a database table quickly, easily, and accurately.
- Data-entry and display forms provide a more structured view of the data than what a datasheet provides.
From this structured view, database records can be viewed, added, changed, or deleted. Entering data
through the data-entry forms is the most common way to get the data into the database table.
- You can use data-entry forms to restrict access to certain fields within the table. You can also use these
forms to check the validity of your data before you accept it into the database table.
- Most users prefer to enter information into data-entry forms rather than datasheet tables; data-entry forms
can be made to resemble familiar paper documents. Forms make data entry self-explanatory by guiding
the user through the fields of the table being updated.
- Display-only screens and forms are solely for inquiry purposes. These forms allow for the selective
display of certain fields within a given table. Displaying some fields and not others means that you can
limit a user’s access to sensitive data while allowing inquiry into other fields.
Reports
- Reports present your data in printed format. You can create several different types of reports within a
database management system. For example, your report can list all records in a given table, such as a
student table. You can also create a report that lists only students who have KCPE marks which is greater
than 360 marks (meets a given criterion). You do this by incorporating a query into your report design.
NB:-
When you design your database tables, keep in mind all the types of information that you want to print. Doing so
ensures that the information you require in your various reports is available from within your database tables .
Macros
- It automates frequently performed procedures or tasks. For example if you frequently use a particular
form when you start a database program, one needs to create a macro that automates the opening of the
form.

Programming module
- When a database becomes more and more complex, one needs a more powerful tool than the macros to
automate the database operations further.
- Most database software come with their own computer languages associated with them. For example
Microsoft Access comes with a language called Visual Basic included as a Module in the software. Using
this feature, you can create a program that will print a query result over and over again until a certain
condition is true.
Example:-
Print Student Report until Number of Students = 40
Pages
- Lets you publish live forms to a corporate intranet

DATA ORGANIZATION IN A DATABASE

AGHS COMPUTER STUDIES ©2012 TOPIC: DATABASES NOTES PAGE 7


One of the functions of a database is to organize data for easy access, retrieval and manipulation. Data is
organized from the simplest form called a value to a very complex structure called a database.
This include:-
Value
- At the intersection of a row (record) and a column (field) is a value— the actual data element. For example,
John, the First Name in the first record, represents one data value.

Fields
- A field is a character or a logical combination of characters that represent a data item. For example, in a class
list, the student name is a field.
Records
- A record is a collection of related fields that represent a single entity. For example students’ performance
worksheet that may contain student’s name, class, admission number, subjects he/she doing, total marks,
average grade etc.
Tables
- It is a collection of related records. For example, the students’ file in a school database contains the
details of all the students in the school.
Database
- This is the highest in data organization hierarchy that holds all related files or tables. For example, a
school database may contain students and staff tables/files.

Summary:-

Fields
Value

AdmNo Name Class Eng Kisw Math Total


7787 Joyce F1M 67 89 75 231 Records
8779 Bentor F1J 69 69 94 232
8090 Joy F1M 89 74 75 238
Students table

CREATING A DATABASE USING MICROSOFT ACCESS


- Microsoft Access is a package in Microsoft Office Suite used for creating and manipulating databases.
Currently the available versions of Access are Access 97/2000, Access XP, 2002, 2003 and 2007.
- Versions higher than 2000 always use Access 2000 as the default compatibility mode.
- We shall use Access 2007 to create databases supported by Access 2000.
Starting Microsoft Access
To create a new database:
i. Click Start, point to Programs, Microsoft Office and then Access 2007.
ii. From the resulting window displayed – Getting started with Microsoft Access
iii. Click on New Blank Database
iv. Select the location where the database will be created, type the database name then click Create.
v. Microsoft Access database objects window is displayed, from which you can choose the type of object
you wish to create such as tables, forms, macros, module, queries, reports etc.

MICROSOFT ACCESS 2007 SCREEN LAYOUT


Like any other application packages discussed earlier, Access application Window has a title bar, menu bar,
toolbars and status bar. However instead of having a work area like that of Ms Word or Excel, it provides the user
with an object window from which you chose the data type of an object to work with such as tables, queries,
forms, reports etc.

Microsoft Access application window

AGHS COMPUTER STUDIES ©2012 TOPIC: DATABASES NOTES PAGE 8


A B C D E

F
A – Office button
B – Menu bar
C – Standard toolbar
D – Title bar
E – Object window
F – Status bar.
Form the application window, in the menu bar it has different features used for different purpose.
Under HOME on the menu bar, a list of menus will be displayed which includes:-
- View, Clipboard, Font, Rich text, Records, Sort and Filter, Find etc.
Under CREATE:-
- Tables in design view, Forms, Reports and others which include Macros, Modules, Query design and
Query wizard.
Under EXTERNAL DATA – this allows one either import some data from other application packages like Excel,
Word etc. This includes:- Import, Export, Collect data and Share points.

Under DATABASE TOOLS


This includes:-
- Macros – Visual basic, Show or Hide – Relationships, Message bar, object dependencies etc. Analyze,
Move data – SQL server, Access Database, Database tools – Switchboard manager, Set database
password, Encode/Decode database, Administer – Users and permission, Replication options.
Under DATASHEET
They include:-
- Views – (design view or datasheet view), Fields and Columns, Data type and formatting, Relationships.
Office button
- When one clicks the office button, a drop down list will be displayed containing the following commands:-
New, Open, Convert, Save/As, Print, Manage, E-mail, Publish and Close database.
EXITING FROM ACCESS
- Like any other application discussed earlier, one can exit from Microsoft Access by pressing Alt + F4 or
on Office button select close database.
GUIDELINE ON DESIGNING GOOD DATABASES

AGHS COMPUTER STUDIES ©2012 TOPIC: DATABASES NOTES PAGE 9


A good database design mean a better storage, security and little maintenance effort. To design a good
database:-
i. Carefully study the requirements of the user in order to define all the data inputs, outputs and relationship
requirements.
ii. Design a draft database on the paper to determine the number of files or tables required.
iii. Divide the information into separate fields, records and tables to allow flexibility in manipulating the
database. The process of dividing information into independent tables to avoid repetition of data entries
items is referred to as normalizing a database.
iv. Define a field for each table that will be used to identify each record uniquely. This field is referred to as a
primary key.
v. Give the most important fields the first priority when constructing a table. Important fields are those that
are used in sorting and querying the database.
vi. Design data entry forms needed for the database.
NB: Database normalization is the process of organizing the fields and tables of a relational database to
minimize redundancy and dependency. Normalization usually involves dividing large tables into smaller (and
less redundant) tables and defining relationships between them. The objective is to isolate data so that
additions, deletions, and modifications of a field can be made in just one table and then propagated through
the rest of the database using the defined relationships.
Creating a table structure
To define a table structure:-
a. On the menu bar, click on CREATE; from the resulting list under tables click Table design; by default
Microsoft Access starts Table1.
b. Using the grid displayed, enter a unique name for each field in the table. A field name must start with a
letter and can be up to a maximum of 64 characters including letters, numbers, spaces and punctuation.
c. Choose appropriate data type before adding the next field. By default Microsoft Access inserts Text as a
data type. The data types include: - Text, Memo, Number, Date/Time, Currency, Auto number, Yes/No,
OLE object, Hyperlink and Lookup wizard.
d. To save the table, click on office button the select Save/As from the pull down menu. (Clicking save icon
which resembles a diskette on the title bar)
e. Access will ask you whether you want to create a Primary key, click Yes. You can also select an icon of
primary key under Tools.
DESCRIPTION OF FIELD DATA TYPES
The type of data to be used in a database must be clearly defined for the purpose of manipulation and storage.
For example if the field is to be used for calculation, it must be defined as a number. The data types in Access
includes:-
Text
- It is any type of data that is simply characters. These characters comprise alphanumeric characters,
meaning numbers (0 through 9) and characters (A to Z, a to z). Names, addresses, and descriptions are all
text data, as are numeric data that are not used in a calculation (such as telephone numbers, Social Security
numbers, and ZIP codes).
- Although you specify the size of each text field in the property area, you can enter no more than 255
characters of data in any text field.
- Access uses variable length fields to store its data. If you designate a field to be 25 characters wide and
you use only 5 characters for each record, then that is all the space you will actually use in your database
container. You will find that the .MDB database file can get large quickly but text fields are not the cause.
However, rather than allow Access to create every text field with the default 50 characters or the
maximum 255 characters, it is good practice to limit text field widths to the maximum you believe they
will be used for. Names are tricky because some cultures have long names.
- However, it is a safe bet that a postal code might be less than 12 characters wide while a U.S. state
abbreviation is always 2 characters wide. By limiting the size of the text width, you also limit the number
of characters the user can type when the field is used in a form.

The Memo
- It is a data type that holds a variable amount of data from 0 to 65,536 characters for each record.
Therefore, if one record uses 100 characters, another requires only 10, and yet another needs 3,000, you
use only as much space as each record requires.
The Number
- It is a data type that enables you to enter numeric data; that is, numbers that will be used in mathematical
calculations. (If you have data that will be used in monetary calculations, you should use the Currency data
type, which enables you to specify many different currency types.)
The Date/Time

AGHS COMPUTER STUDIES ©2012 TOPIC: DATABASES NOTES PAGE 10


- It is a data type that can store dates, times, or both types of data at once. Thus, you can enter a date, a
time, or a date/time combination. You can specify many types of formats in the property entry area and
then display date and time data as you prefer.
The Currency
- It is a data type that enables you to enter numeric data; that is, numbers that will be used with only two
decimal places and can be used for mathematical calculations. You can specify many different currency
formats with this data type. (If you have data that will be used for non-Currency, numeric calculations, you
should use the Number data type.) Used when dealing with fees balance, amount sold etc.
The AutoNumber
- It is a data type that stores an integer that Access increments (adds to) automatically as you add new
records. You can use the AutoNumber data type as a unique record identification for tables having no
other unique value. If, for example, you have no unique identifier for a list of names, you can use an
AutoNumber field to identify one John Smith from another.
The Yes/No
- It is a data type that holds logical data that has one of two values and that can, therefore, be expressed as
a binary state. Data is actually stored as –1 for yes and 0 for no. You can, however, adjust the format
setting to display Yes/No, True/False, or On/Off.
- When you use a Yes/No data type, you can use many of the form controls that are especially designed for
it.
The OLE Object
- It is a data type that provides access for data that can be linked to an OLE server. This type of data
includes bitmaps (such as Windows Paint files), audio files (such as WAV files), business graphics (such as
those found in Access and Excel), and even full-motion video files. Of course, you can play the video files
only if you have the hardware and necessary OLE server software.
The Hyperlink
- It is a data type field holds combinations of text and numbers stored as text and used as a hyperlink
address. It can have up to three parts: (1) the visual text that appears in a field (usually underlined); (2)
the Internet address — the path to a file (UNC, or Universal Naming Convention, path) or page (URL or
Uniform Resource Locator); and (3) any sub-address within the file or page. An example of a sub-address
is the name of an Access 2000 form or report. Each part is separated by the pound symbol (#).
The Lookup Wizard
- It is a data type that creates a field that enables you to use a combo box to choose a value from another
table or from a list of values. This is especially useful when you are storing key fields from another table in
order to link to data from that table. Choosing this option in the Data Type list starts the Lookup Wizard,
with which you define the data type and perform the link to another table. You learn more about this field
type later.
FIELD PROPERTIES
- When you create more and more complex tables, one will be required to use field properties to specify
finer details related to fields and table entries expected.
- The field properties depend on the type of field selected. For example, when click on a Text field, then
the General tab, you will be able to see the field properties associated with it.
The field properties include:-
Field size
- It allows the user to set the number of characters in a field instead of the default value 255. For numeric
fields one uses properties such as Integer, Long integer, Byte, Single and Double.
Integer and longer integer – Accepts numbers with no decimals.
Byte: - it accepts only numbers ranging between 0 and 255.
Single and double: - it accepts numbers with decimals. Single accommodates up to 38 decimal places while
double, accommodates up to 308 decimal places.

Format
- It determines how information appears on the screen when printed. For example, one can format a
number to scientific, currency, percentage or general format.
Decimal places
- For number and currency fields, one can specify the number of decimal places.
Input mask
- It automatically formats the field entry into a specified format. For example, one can enter a number such
as 02000100409874 and the input mask is set as 00-(00000)-000000, it is automatically displayed as 020-
(00100)-409874. This property is mostly used to format phone numbers and address entries.
- Others include – social security number, zip code, extension, password, long time and date, short time
and date, medium time and date etc.
- NB: - The input mask applies only to text and date/time data types.

AGHS COMPUTER STUDIES ©2012 TOPIC: DATABASES NOTES PAGE 11


Caption
- This is a more descriptive name (label) for a field to be used in a table or a form display. For example, the
caption for StudName could be Student Name.
Default value
- It is a value that appears automatically in the datasheet or form if nothing is entered by the user to change
it. For example, =Date ( ) automatically displays the current date in a date field.

Validation rule
- It is a logical expression that restricts the values to be entered in a field. For example, one can restrict
marks entered in a field to be between zero and a hundred, enter >=0 And <=100.
Validation text
- It is a message that appears once the validation rule is violated. For example, you may create a validation
text for the above validation rule to display “Please enter a number between 0 and 100” whenever the
user enters a value outside this range.
Required
- It determines if an entry must be made in the field before you proceed to the next field or record. For
example, if a primary key is required, one must enter it before you proceed.
Allow zero length
- It allows the user to proceed without making any entry in the field set as Zero length.
Indexed
- An index facilitates the organization of records for easy search. A primary key is an example of an index
set to No duplicates.

ENTERING A FIELD DESCRIPTION


- The field description is completely optional; you use it only to help you remember a field’s uses or to let
another user know its purpose. Often you don’t use the description column at all, or you use it only for
fields whose purpose is not readily recognizable.
- If you enter a field description, it appears in the status bar whenever you use that field in Access—in the
datasheet or in a form. The field description can help clarify a field whose purpose is ambiguous or give
the user a fuller explanation of the values valid for the field during data entry.
PRIMARY KEY AND INDEXES
An index is a key(s) used to speed up searching and sorting records in a table, while a primary key is an index that
uniquely identifies each record stored in the table.
Advantages of a primary key:
Besides being a common link field between tables, a primary key field in Access has these advantages:
a. It creates an index for the table that greatly speeds up queries, searches, and sort requests.
b. It prevents the user from making null - When you add new records, you must enter a value in primary key
field(s). Access will not allow you to enter Null values, which guarantees that you’ll have only valid
records in your table.
c. Used to order records and control redundancy - When one adds a new record(s) to a table that has a
primary key, Access checks for duplicate data and doesn’t enable you to enter duplicates for the primary
key field — thus it maintains its integrity.
d. By default, Access displays your data in the order of the primary key.
e. Enables a relationship between tables so that they can be joined.

An index is a special internal file that is created to put the records in a table in some specific order. For instance,
the primary key field in the tblContacts table is an index that puts the records in order by idsContactID field.
Using an indexed table, Access can display records in a specific manner and quickly find any record within the
table using the index.

To set a primary key: -


The primary key can be created in any of four ways: -
✦ Select the field to be used as the primary key and choose Design ➪Primary Key icon displayed on the toolbar.
✦ Select the field to be used as the primary key and select the Primary Key button (the key icon) in the toolbar.
✦ Right-click the mouse to display the shortcut menu and select Primary Key.
✦ Save the table without creating a primary key, and Access automatically creates an AutoNumber field.
Alternatively
1. Open the table in design view.
2. Select the field you want to set as the primary key by clicking in the row header to the left of the Field
Name.
3. Click Primary key button on the toolbar displayed under Design from the menu bar.

Primary Key

AGHS COMPUTER STUDIES ©2012 TOPIC: DATABASES NOTES PAGE 12


To set another field as an index other than the primary key:-
1. Open the table in design view.
2. Click Design from the menu bar. From the menu displayed under Show/Hide, click Indexes.
3. The index design grid is displayed on the screen as shown below.
4. In the Index Name column, type the name of the index.
5. In the Field Name column, select the corresponding fieldname.
6. In the Sort Order column, select Ascending or Descending and then close the window.

Index design window

MANIPULATING DATA IN A TABLE / WORKING WITH DATABASE TABLES


Adding new records:-
- In Access, a record entry into a table is automatically saved once you move to a new row.
To enter records into a table:-
1. Double click the table icon. The table is displayed in datasheet view.
2. On the menu bar, click home; from the menu displayed under Records, select NEW record (or by clicking
the New icon). The following symbols will appear at the row header: -
An arrowhead indicates that no new data entry or edit is pending;
Pencil symbol indicates that the current record entry is not yet saved;
Asterisk symbol marks a blank record below the current entry;
Record locked indicates that the current record is being edited by another user in a multi-user or
networked environment.

AGHS COMPUTER STUDIES ©2012 TOPIC: DATABASES NOTES PAGE 13


Asterisk symbol Pencil symbol Arrowhead

New record entry

Deleting records
To delete a record:
1. Click the record you want to delete.
2. Click Home from the menu bar, under Records click Delete or Delete records. Alternatively right click at
the top left corner of the table; from the menu displayed select Delete Record.
3. A message appears, click Yes to confirm deletion.
Editing fields
To edit a field:-
a. Double click the field you want to edit.
b. Replace the cell content.
Searching for records
To find and replace a field:
1. On the menu bar, click Home; from the menu displayed under Find click Find (Ctrl + F) or Replace.
2. In the “Find What” and “Replace With” boxes, type the field to search for and replace with respectively.

NB:-
- You can use wildcards e.g. asterisks (*) if one is not sure of the search phrase. For example, if you wish to
search for all names that start with letter “J” in a Students table, type J*. All names that start with letter J
such as John, Jane, Joy, Joyce and James will be displayed
COPYING AND MOVING RECORDS
1. Select the record(s) to be copied or removed.
2. Under Home menu click Copy icon under clipboard to create a copy or click Cut icon to move.
3. Open the target datasheet. Under clipboard click Paste icon.
Sorting records
a. In datasheet view, select the records to be sorted.
b. On the Home menu under Sort and Filter, click Filter. From the menu displayed select either (Sort
Smallest to Largest / Sort Largest to Smallest).
Filtering records
- Use the same procedure like the one used in sorting records.
- Under sort and filter, select the type of filter; by selection or advanced.
- Under advanced; select the type of filter you want to use. Either Filter by Form; Apply Filter/Sort,
Advanced Filter/Sort.

AGHS COMPUTER STUDIES ©2012 TOPIC: DATABASES NOTES PAGE 14


FILTERING RECORDS (USING ACCESS 2000 OR 2003)
a. In datasheet view, select the records to be filtered.
b. On the Records menu, point to filter.
c. Select the type of filter you want to apply.
d. In the datasheet, click a down Arrow of the field to set the filter option.
e. Click Apply filter button on the toolbar.
f. In the index name column, type in the name you want to give to the index.
g. In the Field Name column, click the cell to display a drop down list. From the drop down list, select the
field to use as an index.
h. In the Sort Order column, select either ascending or descending.
i. In the lower portion, specify whether you want to make the field a primary key by selecting yes for
primary and unique, and Ignore Nulls to ensure that data is entered into the field before proceeding.
j. Click the close dialog box.

MODIFYING A DATABASE
Modifying datasheet
To adjust the column size:
1. Point to the column border between the field’s header, then drag to the required size.
2. Alternatively, under Records in Home menu, click on More; from the pull down menu select column
width, a dialog box will be displayed from which you can enter width size. Default value is 11.75.
To adjust row height:
1. Point to the border between two rows in the row header and then drag.
2. Alternatively, under Records in Home menu, click on More; from the pull down menu select row height, a
dialog box will be displayed from which you can enter height size. Default value is 14.25.
To reorder fields:
1. Select the column of the field you wish to move by pointing to the desired field name.
2. Drag the column right or left to the top of the field where you want your field to appear and then drop.
Modifying table structure
When one creates a table, he/she may need to add more fields, remove some fields, reorder the fields or change
fields data types and properties. Before modifying the table, it is important to save a copy to avoid losing
everything in case you make a mistake.
To make a copy of the table:-
1. On the Office button, select Save As from the pull down menu. From the menu displayed besides select
Save Object As.
2. In the dialog box that appears, type the name of the table in the Save a copy as; e.g. Student table As
Student Details and then click Ok.
To modify the original table:
i. Open the table in design form by clicking the button that looks like a pencil and a set square under View
in the Home menu.
ii. Select design view from the pull down menu.
iii. Select the field(s) to be modified and make the necessary changes.
iv. Click the save button to save the changes.

NOTE:
If a table contains data and you make changes to the field data types, Ms Access may refuse to implement the
changes. To avoid this problem, exit without saving and delete all the records from the table then return to the
design view.
Importing tables:-
One can import a table from another database or a spreadsheet into the database. To import a table or a
worksheet:-
1. Select External Data from the menu bar; under Import, click Excel. From the resulting dialog box, select
the source and destination of the data.
2. Click Browse. File open dialog box will be displayed; look in one of the Save in folders and then select the
table(s) you wish to import and then click Open. Click Ok.
3. If the Spreadsheet contains more than one worksheet, select one of them then click next.
4. Specify the information about each of the fields you are importing. Click next.
5. Define the primary key of data in the worksheet. Choose my own primary key. Click next.
6. Click Finish.

AGHS COMPUTER STUDIES ©2012 TOPIC: DATABASES NOTES PAGE 15


FORM DESIGN
A form is an interface that enables the user to view and make data entries into an underlying table or query more
easily.
Forms can be designed for different purposes:-
a. Displaying and Modifying data
- Forms can be used to add, modify or delete information in the database.
b. Accepting User Input
- They can be designed to limit the user by designing them to accept only certain data values, using data
validation. Data values can also be provided to help automate data entry by using option groups, pop-up
list, drop-down lists, etc.
c. Controlling Application flow
- They can be designed to work with Macros and Modules to automate a sequence of actions or to display
specified information. Buttons can be placed on forms to run a macro attached to it, or to perform a VBA
procedure when clicked.
d. Displaying Messages
- They can be used to display messages including warning or error messages.
e. Printing Information
- Reports are the ones used for printing information but forms can also be used to print information.
CONTROLS
- In Microsoft Access, a form is designed using graphical objects called controls. A control is a visual
object such as a text box, check box, command button or shapes that you place on a form design grid
to display data or perform actions.
- Forms contain tools that are designed to help users navigate and utilize the form. There are three
categories which include:-
a. Bound
b. Unbound
c. Calculated
Bound
- These controls are fields of data that come from a table or a query. A form must have a bound control for
each field that you display on the form. In Access one cannot create a calculation in a bound control.
Unbound
- It is a control that is not connected to any source. The control contains a label or a text box. One uses
unbound controls to explain or identify other controls on the form. Calculations can be created from an
unbound control.
Calculated
- These are any values calculated in the form, including totals, subtotals and average.
You can design or modify a form layout by dragging these controls to the required position.

The figure below shows a form designer for a table called STUDENT DETAILS

Unbound controls

Bound control

AGHS COMPUTER STUDIES ©2012 TOPIC: DATABASES NOTES PAGE 16


Form layout
- All forms must have a detail section. These include Detail, Page Header, Page Footer, Form Header and
Form Footer sections.
Form Header:-
- It displays information that remains the same for every record such as a title for the form. It appears at the
top of the screen in Form view and at the top of the first page when printed.
Page Header:-
- It displays information such as a title or column headings, at the top of every printed page. Page headers
appear only on printed forms.
Page Footer:-
- It displays information, such as the date or page number at the bottom of every printed page. Page footers
appear only on printed forms.
Detail
- This is the area where one places the controls that one wants to use both bound and unbound controls.
Form Footer
- It displays information that remains the same for every record such as command buttons or instructions
for using the form. A form footer appears at the bottom of the screen in Form View or after the last detail
section on the last page when printed.

Creating a form layout using a Wizard


To create a form layout, one can either use the form wizard or start from scratch. When using a form wizard, you
can create either a Columnar, a Tabular, a Datasheet or a Justified form layout
- Columnar form: - The fields for each record are displayed down a column i.e. each value displayed on a
separate line with field labels to the left.
- Tabular: - Records are displayed from left to right across the page and labels appear at the top of column.
Each row represents a new record.
- Datasheet: - The form resembles a table datasheet view.
- Justified: - One record occupies the whole form.
To create a form using the form wizard:-
a. Open the database for which the form is to be created e.g. “Patients table”.
b. Click Create on the Menu bar, from the resulting objects displayed(Tables, Forms, Reports and Others);
under Forms, select More Forms by clicking on the arrow pointing down –(Form wizard, Datasheet,
Modal Dialog and Pivotal Table) will be displayed from the pull down menu. Select Form wizard. Form
wizard Dialog box will be displayed.
c. Select the name of table or query you want to create a form under Table/Query.
d. From the available fields in the Table/Query you have chosen, select the fields you want to add on your
form by clicking > button or clicking >> to add all fields, then next.
e. The layout dialog box displayed select the layout you want to use e.g. Columnar, Tabular, Datasheet, and
Justified. Click Next.
f. From the style dialog box, select the style you would like to use e.g. Access 2003, Access 2007, Vista,
Apex, and Office etc. click Next.
g. In the form Title dialog box, type the name of the form then click Finish.
NB:-
From the option button displayed in the dialog box, one can open the form to view or modify the form design.
Ms Access will automatically display the form on the screen.
Creating a form from scratch
a. Open a database.
b. Under Create select Form design icon displayed. A blank form in design view will be displayed.
To add controls onto a form;
Forms can be made user-friendly by adding controls that are well defined and self-explanatory to the end user.
Controls can also greatly improve the appearance of a form.
a. When in design view, display the form that you would like to edit.
b. Click Design from the menu bar. Under controls select one of the controls.
c. Drag and drop the various controls like check box, command button, option button, labels, logo, combo
box, tab control, list box etc.
d. Save the form by clicking on the save button.
Data manipulation in a form
Adding and displaying records
- The form provides the user with navigation buttons located at the bottom that can be used to navigate the
form as shown below:-

AGHS COMPUTER STUDIES ©2012 TOPIC: DATABASES NOTES PAGE 17


1 2 3 4 5

The functions of the buttons can be summarized as shown below


1. Displays the first record in the table.
2. Displays the previous record.
3. Displays the next record.
4. Displays the last record.
5. Used to add a new record.
Formatting controls
To format controls on a form:-
1. Open the form in design view.
2. To resize, click the controls then position the pointer on the outline of the control then drag to the
required size.
3. To move, click control and position the pointer onto the place holder or inside control, then drag to the
required location.
4. If you want to format the text by changing its color, bold, italic, font size and type; select the various
formatting tools under Font in Home menu.
Removing controls
1. Open the form you wish to edit in design view.
2. Select the control you would like to remove and the Delete key.
NB: - One must be careful when removing controls, since Access does not prompt you to verify the removal of some
controls.
Adding Graphics to Forms
Graphics and pictures can be used to add style to forms. Access provides the flexibility to add graphics files from
a number of sources such as scanned pictures, Office clipart, and graphics created using graphics packages.
Steps:-
a. Open the form in Design View.
b. Under design, click the Image icon in Controls.
c. With the image pointer, click on hold while you drag a rectangle in the location the picture on the form.
d. From the Insert Picture dialog box, locate the folder that contains the graphics or image that you want to
insert. Double click the file you want to insert.
e. Resize the image by dragging the handles.

CREATING SUBFORMS
- Sub-forms are used to display data from several tables that have a one-to-many relationship. The main
form displays data from the parent table, and the sub-form from the child table. For example, to display
all the items on one order, a sub-form would be used.
Steps for creating a sub-form
- Open the form in design view.
- Under design in controls, select sub-form/sub-report icon displayed.
- Follow the steps on the screen that will take you through sub-form wizard.
- Select the table/query from which you want to draw the data for the sub-form.

QUERYING A DATABASE
- Queries are the fastest way to search for information in a database.
- A query is a database feature that enables the user to display specific records as well as perform
calculations on fields from one or more tables.
One can analyze a table(s) by using either a select query or an action query. Select query is the one we shall
discuss.
Select query
It is the most common type of query used for searching and analyzing data in one or more tables. Select query
lets the user specify the search criteria and the records that meet those criteria are displayed in a dynaset or
analyzed depending on the user requirements.

AGHS COMPUTER STUDIES ©2012 TOPIC: DATABASES NOTES PAGE 18


Action query
They are queries that are used to make changes to many records at once. They are mostly used to delete, update,
add a group of records from one table to another, or create a new table from another table.
Types of action queries include:-
a. Update query – creates a query that will automatically make changes, to records that match users
specifications.
b. Append query – adds data in a table from one or more tables.
c. Delete query – deletes specified records from one or more tables.
d. Make table query – creates a query that will make a new table with the data that fits users criteria.

Creating a select query


a. Ensure that the database you want to create a query for is open.
b. Click Query design under Create on the menu bar. One can also choose query wizard.
c. To design from scratch, click query design. Show table dialog box appears from which you can add a
table(s) you wish to create a query from.
d. Click the table from the table/query list and then click Add.
e. Click close to close Show table dialog box.
f. The query design grid opens. In Ms Access it is called Query-by-Example. This allows the user to design
a query.

Parts of the query grid


Field row – fields from a table(s) to be used are arranged in this row. Each field occupies its column.
Table row – indicates the table providing the fields.
Sort row – clicking the down arrow inn the sort cell, one can specify the sort order i.e. ascending, descending or
no sort.
Show row – clicking the show box, one specifies whether to display the field in the query results. If the box is not
checked, the field will not be displayed.
Criteria row – these is where one types conditional statements that will be used by the query to display specific
records.
Or row – used to specify an alternative condition e.g. if you want to display records with a field called Schools,
with items Alliance or BG Ngandu, type Alliance in criteria cell and BG Ngandu in the Or cell.
Total row – allows one to group data in the active query or perform summary calculations. Some of the
calculations one can perform includes: - sum, count, average, minimum, maximum, standard deviation etc.
To add fields into the query grid:-
Open the query in design view.
From the field list of the underlying table, drag each field and place it in the field row.

Specifying the search criteria


- One must enter conditional statements in the criteria row when searching for a particular set of records.
For example from the employees table; salary field – one can display all people who are earning more
than 15,000 by typing >15,000 in the criteria row, salary column.
- When defining criteria, use either relational or logical operators. Relational operators include: - less than
(<), greater than (>), greater than or equal to (<=), not equal to (< >) and equal to (=). Logical operators
include: - AND, OR and NOT.
AND – used when one wants to display values in a specific range. Example, to display records from the
employees table with salaries above 30,000 but less than 60,000, type, >30,000 AND <60,000 on the
criteria row in the salary column. All the employees meeting the condition will be displayed.
OR – used when one wants to get either one of two values. Example, to display employees who are either
in Nairobi OR Embu.

AGHS COMPUTER STUDIES ©2012 TOPIC: DATABASES NOTES PAGE 19


Between – used when one wants to display data in a particular range. Example, instead of typing, >30,000
AND <60,000, type Between 30,000 And 60,000.
NOT – used when one wants to list all records except those that one does not want to see. Example NOT
60,000 in the salary column of the employees table, all employees’ records will be displayed except those
with their salary as 60,000.
LIKE – used to display records that one is not sure of the field name but at least he/she can remember a
few characters. One can also use wildcards.
Wildcards are special symbols mostly an asterisk and a question mark used in place of other characters.
Example –to display all names starting with “Sm” followed by other characters, type Like Sm?
Like*/*/2008 lists records created in 2008 regardless of the day or month.
Saving and running the query
Click the save button on the standard toolbar or save command from the Office button drop down list.
In the name box that appears type in the name of the query then click Ok.
To run the query in design view, click the Run button on the toolbar as shown below.
Run button Total button.

Run Query
You can also view the results of your query any other time by selecting the query, then clicking the Open button
from the database window.
Sorting the dynaset
To sort a dynaset:
1. In the sort row, click the down arrow that appears to specify the sort order i.e. ascending or descending of
the desired field.
2. Display the dynaset.
Creating a select query
a. Open the database that contains the records you want to update.
b. On the Create tab, in the Other group, click Query Design.

c. The query designer opens, and the Show Table dialog box opens.
d. Select the table or tables that contain the records you want to update, click Add, and then click Close.
e. The table or tables appear as one or more windows in the query designer, and the windows list all the
fields in each table. This figure shows the query designer with a typical table.

f. Double-click the fields that you want to update. The selected fields appear in the Field row in the query
design grid.
g. You can add one table field per column in the query design grid.
h. To add all the fields in a table quickly, double-click the asterisk (*) at the top of the list of table fields. This
figure shows the query design grid with all fields added.

AGHS COMPUTER STUDIES ©2012 TOPIC: DATABASES NOTES PAGE 20


Optionally, you can enter one or more criteria in the Criteria row of the query design grid. The following table
shows some example criteria and explains the effect they have on the results of a query.
Note:-
Many of the examples in this table use wildcard characters to make the query more flexible or powerful.
For more information about using wildcards in your queries, see the article Access wildcard character reference.
Criteria Effect
>234 Returns all numbers greater than 234. To find all numbers less than 234, use < 234.
>="Cajhen" Returns all records from Cajhen through the end of the alphabet.
Between #2/2/2007# Returns dates from 2-Feb-07 through 1-Dec-07 (ANSI-89). If your database uses the
And #12/1/2007# ANSI-92 wildcard characters, use single quotation marks (') instead of pound signs
(#). Example: Between '2/2/2007' And '12/1/2007' .
Not "Germany" Finds all records where the exact contents of the field are not exactly equal to
"Germany." The criterion will return records that contain characters in addition to
"Germany," such as "Germany (euro)" or "Europe (Germany)".
Not "T*" Finds all records except those beginning with T. If your database uses the ANSI-92
wildcard character set, use the percent sign (%) instead of the asterisk (*).
Not "*t" Finds all records that do not end with t. If your database uses the ANSI-92 wildcard
character set, use the percent sign (%) instead of the asterisk (*).
In(Canada,UK) In a list, finds all records containing Canada or UK.
Like "[A-D]*" In a text field, finds all records that start with the letters A through D. If your
database uses the ANSI-92 wildcard character set, use the percent sign (%) instead
of the asterisk (*).
Like "*ar*" Finds all records that include the letter sequence "ar". If your database uses the
ANSI-92 wildcard character set, use the percent sign (%) instead of the asterisk (*).
Like "Maison Dewe?" Finds all records that begin with "Maison" and contain a 5-letter second string in
which the first 4 letters are "Dewe" and the last letter is unknown. If your database
uses the ANSI-92 wildcard character set, use the underscore (_) instead of the
question mark (?).
#2/2/2007# Finds all records for February 2, 2007. If your database uses the ANSI-92 wildcard
character set, surround the date with single quotation marks (') instead of pound
signs (#); for example, ('2/2/2007').
< Date() - 30 Uses the Date function to return all dates more than 30 days old.
Date() Uses the Date function to return all records containing today's date.
Between Date() And Uses the Date and DateAdd functions to return all records between today's date and
DateAdd("M", 3, three months from today's date.
Date())
Is Null Returns all records that contain a null (blank or undefined) value.
Is Not Null Returns all records that contain a value.

AGHS COMPUTER STUDIES ©2012 TOPIC: DATABASES NOTES PAGE 21


"" Returns all records that contain a zero-length string. You use zero-length strings
when you need to add a value to a required field, but you don't yet know what that
value is. For example, a field might require a fax number, but some of your
customers might not have fax machines. In that case, you enter a pair of double
quotation marks with no space between them ("") instead of a number.
On the Design tab, in the Results group, click Run.

Modifying and updating a query


To delete fields from the query grid:
i. Open the desired Query in design view
ii. Select the field column you wish to delete
iii. Choose delete columns under Query set up as shown on the diagram above.
iv. Click the Save button to save the changes.
To adjust the column size in a query
i. Open the desired query in design view.
ii. Position the mouse pointer at the boundary that separates columns, then drag it to the required size.
Alternatively, double click the boundary to autofit cell content.
iii. Click the Save button to save the changes.
To modify a criteria statement, select query:
i. Open the desired query in design view.
ii. Modify the criteria statements as desired
iii. Click the save button to save the changes.
iv. To test whether the changes have been effected, click the Run button to display the results of the query.
Performing calculations in a query
Unlike tables, queries let the user perform mathematical calculations on numeric data. You can perform
calculations in a query by using the Total functions or by creating basic formulas.
Creating basic formulae
To create a formula that calculates the total marks in an underlying table e.g. Exams table
1. Open the query in design view.
2. In an empty cell, type an expression that includes a field name such as
Total: ([Physics]+[Maths]+[Chemistry]+[Computer studies]) shown in the diagram below.
3. You can then set the criteria, and other query options.
4. Save the query and run it. The results of the calculations will be displayed in the dynaset as shown in
figure number two. However, this field is not added to the underlying table(s) because query results must
always be based on the most current data in the database.

Fig. 1
Creating calculated field

Fig. 2
Results of the calculated fields
Using Total functions
- With a query, one can analyze all record fields using the inbuilt functions such as Sum, Average, Minimum
and Maximum etc.
To use the total functions:
1. Open the query in design view.
2. Click the Totals button on the query toolbar.
3. Select the field you want to analyze.
4. For each field to be analyzed, click its cell in the Total row, and then select any of the functions.
Sum: - adds all the numerical data items.
Avg: - calculates the mean of all numeric data items in the field column.

AGHS COMPUTER STUDIES ©2012 TOPIC: DATABASES NOTES PAGE 22


Min: - returns the minimum value from the field column.
Max: - returns the maximum value from the field column.
Count: - returns the number of items field column.
5. Set criteria and other options, then click run to preview the results.
6. Save the query.
Printing a query
i. Open the database window of the database containing the query you want to print.
ii. Select the query you want to print and then open the query.
iii. On the Office button drop down list, click print. Set the printing options then click OK button.

Creating queries based on multiple tables.


If the fields used come from more than one table in a query, there should be a common link between the tables.
There are three types of relationships one-to-one, one-to-many, many-to-many.
a. One-to-one relationship: - for a particular field in one table (the main table), there is only one matching
record in the related table and vice versa.
b. In a one-to-many relationship, for a particular field in one table, there are several matching records in
another table. It is the most common type of relationship. Example, a person can make one order, or
several orders. In this case, there is only one record with that person’s details say in customers table, yet
there are several records related to the same person in the Orders table.
c. In a many-to-many relationship, for particular records in one table, there are several matching records
in the other table and vice versa. This is not common.

Defining relationship between tables


a. Make sure the database is open.
b. Select Database tools on the menu bar. From the menu displayed select Relationships. The relationship
dialog box will appear (show table).
c. Select the table to add, then click the Add button.
d. To create relationship, click on the common field and drag it to the second table. The fields used to
create the relationship must be of the same type and properties.
e. To Enforce Referential Integrity, under Design from the menu bar, Under Tools select edit relationship.
Alternatively, right click the line joining the two tables, then click Edit. An Edit relationship dialog box
will be displayed.
f. Make sure Enforce Referential Integrity is checked to ensure that all records entered in the related table
exist in the primary table.
g. Click Ok to close the Edit relationship dialog box.

Edit relationship dialog box.

To create a query based on related tables:-


i. Start the database window and click the Query design.
ii. Select the design view and then click OK.
iii. From the show table dialog box, click the tables you want to base your query on and then click Add.
iv. Relationship between various tables will be displayed.
v. Save and Run the query.
Creating reports and labels
Reports are used to summarize and present information from a database while labels are used for identity
purpose. A good database software should enable the user to generate reports and labels.
Creating reports

AGHS COMPUTER STUDIES ©2012 TOPIC: DATABASES NOTES PAGE 23


Like in forms, a report layout is also designed by placing controls on to the report designer as shown below.
Parts of a report
a. Report header – this contains unbound controls that display title of the report.
b. Page header – contains heading or labels data items to be displayed in every column.
c. Detail – holds bound controls that display data items for the table or query it was created from.
d. Page footer – holds a control that is to be displayed on every page such as the page number and date. For
example =NOW ( ) displays the current date and time as set in the system clock.
e. Report footer – used to display summary from a report such as the grand total for numerical data in a
particular field column.

Report layout designer

Creating a Report using report wizard


Report wizard takes the user through a number of steps by answering a few questions and Ms Access
automatically does the rest.
To create a report layout
1. Ensure the database is open.
2. Click the Report Wizard under Reports in the Create menu.
3. In the Report wizard dialog box displayed, select a table or query, then the fields to be added to the
report then click Next.
4. The wizard asks you whether you wish to add grouping. Grouping is used to classify records using a
particular field. For example, to categorize Student Admission number in a school database according to
Admission number double click the field, then click next.
5. In the dialog box that appears, select the Sort option if you want to sort the records. Click the Summary
options button in case you want Ms Access to perform calculations on numerical fields.
6. In summary options dialog box, select the Summary options you want to performed e.g. Sum, Average,
Max and Min as shown in the diagram below.
7. Click OK to close the summary options dialog box, and then click Next.

8. In the layout dialog box, select the type of layout such as stepped and the click Next.
9. In the style dialog box, specify the report style by selecting Access 2007, Access 2003, Office, Metro,
Module, Median, Foundary, Windows Vista etc
10. Finally enter the name of your report, and then click Finish. The report will be displayed on the screen in
print preview mode.

AGHS COMPUTER STUDIES ©2012 TOPIC: DATABASES NOTES PAGE 24


Creating a report in design view
Just like forms, one can create a report in design view by placing controls on the design grid.
Steps for designing a report in design view.
- In the database window, click Blank Report under Reports.
- A blank report will be opened which will be displayed in Layout view. The available fields in other tables
will be displayed.
- Drag each field from the field list to the layout grid and drop it where you want the data column to appear.
- Click Save button after placing the controls.
- In the Save As dialog box, enter the name of the report and click Ok.
- To view the report, click View under Home menu. Select Print Preview from the pull down menu.
Sorting and Grouping
- Sorting and grouping allows one to organize information in a neat and easy-to-read manner. If a report
wizard is used, it will prompt the user to specify how the records should be grouped and/or sorted.
- By default, if one groups data in a field; data will be sorted by that field. One needs to group similar
records in order to perform any calculations on the group.
Example:-
- A report for overall student performance, one can group the marks by subject and by class. This enables
one to determine the overall performance of every class and the subject average.
Using sorting and grouping feature:-

Creating labels
- A label is a sticker or piece of paper put on an item for the purpose of identification. Examples of stickers
are mailing labels, label on the floppy disk where you write your name etc.
- Using the report label wizard, Ms Access lets you easily create labels of different sizes.
Steps
a. Open your database
b. On the database window, click Create on the Menu bar; under Reports select Labels.
c. In the resulting label wizard dialog box, specify the label size and then click Next.
d. From a series of dialog boxes displayed, specify the label size, font, text color, choose the fields to be
included on your mailing label by clicking the arrow > to move to the Prototype label.
e. You can sort your labels by one or more fields in your database by clicking > or >> and then click Next.
f. Enter the name of the Label then click Finish.

Label wizard.
Modifying labels
The way you modify a report or form, one can also modify a label by manipulating the layout controls.
Steps:
a. On the database window under Reports in the Create menu, click Labels or Open existing label and then
click Design View button under View.
b. The label design grid will be displayed. Edit the layout as desired, save and close the design grid.
c. To view the modified label, click the Preview button under the View button.
Printing the reports and labels
Before printing a report or a label, one must set the page options i.e. the margins, paper size and orientation.
a. Open the database that contains the report you want to print.
b. Select the Report you want to print, and then click the Preview button under View.
c. On the Office button, select print from the pull down menu.
d. Set the printer options i.e. the printer type, print range and number of copies.
e. Click Ok to print.

AGHS COMPUTER STUDIES ©2012 TOPIC: DATABASES NOTES PAGE 25


USING ADVANCED ACCESS FEATURES.
Creating Macros
- A macro is a set of one or more actions used to automatically perform particular operations such as
opening a form or printing a report. Macros are used to automate database application.
Advantages of using a macro:-
i. It saves time by automating tasks that are both routine and repetitive.
ii. It reduces errors and increases accuracy, ensuring that tasks are performed consistently.
iii. It makes the forms and reports user-friendly by adding command buttons (that represent macros) that will
enable users to easily manoeuvre between several objects.
iv. Automating the exporting and importing of data to and from outside sources, such as Excel.
To create a macro:-
i. In the database window, click the Macros button. Macro design will be displayed as shown below.
ii. In action column, click to add an action e.g. OpenTable. In the lower part, specify arguments settings for
the action in Action Argument box.
iii. Type an optional comment for the action.
iv. Add more actions to the macro. Actions are executed in the order you list them.
v. Save the macro and run.

Macro design

Enforcing database security


Ms Access provides the user with several data security tools such as encryption, password protection, hiding
database objects and user level security.
Password protection of a database
A password protected database displays a dialog box that requests the password for opening. To set up a
password:
a. Open the database in exclusive mode as shown in the diagram below.
b. On the Database tools menu select Set Database Password.
c. In the Password box, type in a Password.
d. Re-enter the password in the verify box, and then click OK.

AGHS COMPUTER STUDIES ©2012 TOPIC: DATABASES NOTES PAGE 26


Open a database exclusively

Encrypting a database
Encryption compacts a database file and makes it indecipherable by a utility program or a word processor
especially on a networked environment. Encrypting a database does not restrict access to objects by users. To
encrypt a database:
i. Start Ms Access without opening a database because you cannot encrypt or decrypt a database when it is
open.
ii. On the Database tools menu, select Encode and Decode database.
iii. In the dialog box that appears, select the database you want to encode or decode and then click OK.
iv. In the Encrypt database dialog box that appears, specify the location and type the file name for the
encrypted or decrypted database, and then click Save.
Hiding database objects
i. Hide tables, queries, forms and reports and macros from casual users. This method of protection is the
least secure because it is possible to unhide the objects.
To hide objects:-
i. On the Show/Hide list under the Database Tools menu, select Property sheet.
ii. In the dialog box that appears, check Hidden.
iii. Click Apply, and then OK.

Hiding database objects

AGHS COMPUTER STUDIES ©2012 TOPIC: DATABASES NOTES PAGE 27


User level security
This is the most extensive security method especially on a multi-user environment. A database Administrator can
grant specific users or groups’ specific permissions and privileges to tables, queries, forms, reports and macros.
To assign user rights and privileges:
Open the database
a. On the Database tools under Administer Select User and permissions; from the pull down menu select
User Level Security wizard, security wizard dialog box will be displayed and then click Next.
b. Enter the name and workgroup ID (WID) you want for your workgroup information file. One can enter the
name and company (optional). You can make this default workgroup information file or create shortcut to
open security-enhance database.
c. Select objects you want to secure e.g. tables, queries, macros, forms, reports, other or all objects, and
then click Next.
d. Select the groups you want to include in your workgroup information file e.g. Full permissions – the group
has full permissions on all database objects but can’t assign permission to other users. Click Next.
e. If you want to grant the Users group some permission or not you select one of the option buttons. (Yes/No)
and then click next.
f. Click finish after going through the entire process.

Setting up startup options


To customize your database application workplace, there is need to specify how the database is to be loaded.
To set the startup options:-
i. On the tools menu, click startup
ii. In the startup dialog box, set startup options e.g. application title, startup object and other application
window options and then click Ok.

END OF THE TOPIC

AGHS COMPUTER STUDIES ©2012 TOPIC: DATABASES NOTES PAGE 28

You might also like