Database
Database
Field - A Field corresponds to the columns in the table. Fields must be designated as a
certain Data type, whether it is Text, Date/Time, Number, Currency, etc
Record- Records are where the individual pieces of information are stored
2. Forms is a “data entry screens.” They are the interfaces you use to work with your data, and
they often contain command buttons that perform various commands.
3. Reports are what you use to summarize and present data in the tables.
4. Queries- they used to retrieve the specific data from the database table.
Types of Queries
1. Select Queries - A select query simply retrieves the data and makes it available for use. You
can view the results of the query on the screen, print it out, or copy it to the clipboard. Or,
you can use the output of the query as the record source for a form or report.
2. Action Queries. Is a query which performs a task with the data. Action queries can be used to
create new tables, add data to existing tables, update data, or delete data.
CREATING TABLE
Creating a new table
1. Click “create”->Table
2. Click save
3. Type the table name
4. Open the table in design view to enter the field name and
its data type.
5. Open the table in datasheet view to enter the record/ data.
FIELD DATA TYPES
SN NAME USE THIS IF COLUMN/FIELD CONTAIN or Store
1 Text/ Text, combinations of text and numbers or number not
Short text used in calculations such as phone numbers or postal
codes This is for short text (less than 255 characters).
2 Memo/Lo Text, combinations of text and numbers or number not
ng text used in calculations such as phone numbers, or postal
codes. This is for long notes (more than 255 characters).
3 Number Numeric data to be used for mathematical calculations,
except calculations involving money (use Currency type).
4 Date/Time Dates and times
5 Currency involving money details
6 Unique sequential (incrementing by 1) or random
AutoNumber
numbers automatically inserted when a record is added.
7 Yes/No Fields that will contain only one of two values, such as
Yes/No, True/False, On/Off.
How to Delete a record.
If you need to delete only some information but not the
entire record, select only the data that you want to delete
and then press DELETE.
-or-
On the Home tab, in the Records group, click Delete.
Adding Records
You can add records in a table only when you are
in the Datasheet View.
It is not possible to add data in an ‘AutoNumber’
field. Move to the blank record showing on your
table and enter your data, as shown below
FILTERING AND SORTING RECORDS
Filtering
Filtering allows you to view a set of records depending on some criteria
that you may set
Steps:
1. Click filter from home menu
2. Uncheck record to hide
Sorting
the process of arranging the data in an order, order can be
ascending (largest to smallest) or Descending order (smallest
to largest)
Steps:
•Position the cursor in the field on which you want to sort. E.g. to sort by the
lastName, position the cursor in the lastName field
•To sort in ascending order (Smallest to Largest) click on the ascending
•To sort in Descending order (Largest to Smallest) click on the
Descending
CREATE RELATIONSHIPS.
Refers to the field in two or more table
which relate them and are used to join the
tables.
We use primary keys and foreign keys to
create relationships(join tables ).
A primary key is a field or combination of
fields that uniquely identify each record in a
table.
A foreign key is a value in one table that
must match the primary key in another
table.
There are two valid types of relationships:
one-to-one relationship, for every occurrence of
a value in table A, there can only be one
matching occurrence of that value in table B,
and for every occurrence of a value in table B, there
can only be one matching occurrence of that value in
tableA.
- This type appear to a single table
one-to-many relationship, for every occurrence of
a value in table A, there can be zero or more
matching occurrences in table B,
and for every one occurrence in table B, there can
only be one matching occurrence in table A.
Referential integrity ensures that the
validity of the relationship between
two tables remains intact.
It prohibits changes to the primary
table that would invalidate an entry in
the related table.
For example, a school has students.
Each student can make several
payments, but each payment can only
be from one student.
The Students table is the primary table and
the Payments table is the related table.
Students
Student ID Last Name First Name
Primary Key
1 John Smith
2 Mark Adams
3 Valerie Kilm
Payments
Payment ID Student ID Amount Due Amount Paid
Primary key Foreign key
1 1 500 500
2 2 700 300
3 3 500 250
4 2 400 300
5 3 250 250
If you delete Student ID 1 from the Students
table, Student ID 1 is no longer valid in the
Payments table.
Referential integrity prevents you from
deleting Student ID 1 from the Students table.
Also, if the only valid Student IDs are 1, 2, and
3, referential integrity prevents you from
entering a value of 4 in the Student ID field in
the Payments table.
A foreign key without a primary key reference
is called an orphan.
Referential integrity prevents you from
creating orphans.
How to create relationships:
1. Click database tool ->relationship
2. Select the table from dialog box appear
3. Click the field name of fist table and drag to another
related field on dialog appear
4. If did not match, collect them then click the create
Introduction to Queries
Queries are used to view, change and analyse
data in different ways. They can also be used as
the source of records for forms and reports.
Why use queries?
We need queries when we want to ask ourselves
questions about data stored in our tables.
How do they help us?
•In choosing fields
•Choosing records that meet a certain criteria
•In sorting records
•Performing calculations - can create calculated
fields and add data to them.
Creating/Saving Queries
•Open your database
•Select Query option
•Double Click Create Query In Design View
•Select table to query from list, Add, then Close
Table: Drivers
Drivers_ID Last Name First Name Birth Date Hire Date Address
1 Aketch Nancy 12/8/1948 5/1/1992 P.O. Box 4501 Kilosa
2 Mutunga Andrew 2/19/1952 8/14/1992 P.O. Box 6733 Makambako
3 Kasavuli Janet 8/30/1963 4/1/1992 P.O. Box 6747 Madaba
4 Thatcher Margaret 9/19/1937 5/3/1993 P.O. Box 35667 Nyamagana
5 Mulumba Steven 3/4/1955 10/17/1993 P.O. Box 644 Bukoba
6 Wamalwa Michael 7/2/1963 10/17/1993 P.O. Box 876 Buhongwa
7 Koskei Robert 5/29/1960 1/2/1994 P.O. Box 260 Lindi
8 Chepkurui Laura 1/9/1958 3/5/1994 P.O. Box 8955 Nakuru
9 Kitui Anne 1/27/1966 11/15/1994 P.O. Box 754 Bunda
10 Mutuku Caroline 3/5/1973 1/11/2000 P.O. Box 1342 Simiyu
11 Nyambane Walter 12/6/1975 6/15/1999 P.O. Box 7803 Kilwa
12 Wasike Levy 6/13/1978 8/4/2003 P.O. Box 11789 Dsm
Drivers are paid a uniform salary of Sh. 12000/-. Update your table to reflect these details.
Table: Routes
Distance
Route NO (Kilometers) Fare(Tsh.) Destination
305A 384 6000.00 Nyasa
305D 288 4500.00 Mbiga
290B 589 5500.00 Tunduru
290A 512 5500.00 Madaba
514B 189 3000.00 Namtubo
519 487 4000.00 Sayu
514A 350 4000.00 Majengo
609A 615 5000.00 Makambi
609B 710 8000.00 Njombe
609C 542 5000.00 Makambako
1011A 1241 15000.00 Iringa
1011B 1005 15000.00 Maswa
1012A 950 10000.00 mtwara
2011 1600 18000.00 Dar-e-salaam
Table: Vehicles
Drivers First
_ID Last Name Name Birth Date Hire Date Address
1 Nyoni Nancy 12/8/1948 5/1/1992 P.O. Box 4501 Kilosa
2 Mutunga Andrew 2/19/1952 8/14/1992 P.O. Box 6733 Makambako
3 Kasavuli Janet 8/30/1963 4/1/1992 P.O. Box 6747 Madaba
4 Mapunda Margaret 9/19/1937 5/3/1993 P.O. Box 35667 Nyamagana
5 Mulumba Steven 3/4/1955 10/17/1993 P.O. Box 644 Bukoba
6 Wamalwa Michael 7/2/1963 10/17/1993 P.O. Box 876 Buhongwa
7 Bahini Robert 5/29/1960 1/2/1994 P.O. Box 260 Lindi
8 Sombi Laura 1/9/1958 3/5/1994 P.O. Box 8955 Nakuru
9 Kitui Anne 1/27/1966 11/15/1994 P.O. Box 754 Bunda
10 Mutuku Caroline 3/5/1973 1/11/2000 P.O. Box 1342 Simiyu
11 Nyambane Walter 12/6/1975 6/15/1999 P.O. Box 7803 Kilwa
12 Wasike Levy 6/13/1978 8/4/2003 P.O. Box 11789 Dsm
Table: Shifts
Drivers are assigned the following shifts schedules. Add this information in the Shifts table.
5. Save a report.
How to create a report by using the
Report Wizard:
Steps :
1. Open the Report Wizard.
Activate the Create tab.
Click Report Wizard in the Reports group.
The Report Wizard appears.
2. Select tables, queries and fields
When using the Report Wizard, you can use
fields from multiple tables and/or queries if
the tables/queries have a relationship.
Click the down-arrow next to the Table/Queries field and
then click the table from which you want to select fields.
Click a field and then click the single-right arrow to select
a single field, click the double-right arrows to select all
fields, click a field and then click the single-left arrow to
deselect a single field, or click the double-left arrow to
deselect all fields.
Repeat steps 1 and 2 for each table from which you want to
select fields.
Click Next. The Report Wizard moves to the next page.
Group
When using the Report Wizard, you can group data. Grouping
puts all of the values in a field into a group based on the field’s
value. For example, if your data is grouped by the Department
field and the records in the Department field have values such
as Administration, Computer Science, and English. Accesswill
group all of the data for the Administration department
together, all of the data for the Computer Science department
together, and all of the data for the English department
together.
1. Click to select the field by which you want to group
your data. You may not see this page of the wizard if
you are selecting data from a single table.
2. Click Next. The Report Wizard moves to the next page.
Click a field you want to group by.
Click the right-arrow to select a field; click a field and
then click the left arrow to deselect a field. Use the up-
and down-arrows to change the order of the groupings. If
you are only using one table, this may be your first
opportunity to select a field to group by.
Repeat steps 3 and 4 for each field you want to group by.
Click Next. The Report Wizard moves to the next page.
Sort and summarize
By using the Report Wizard, you can create up to four
levels of sort. Access sorts the first level, and then sorts
the second level within that sort, and so on. If you have
grouped your data, you can summarize it by displaying
the sum, average, and minimum or maximum value for
each numeric field. You can choose to have your report
display just the summary data or each detail line and the
summary data. There is also an option that allows you to
display the percent the sum of each group is of the grand
total. All of the fields in your report may not fit on a
single page. You can have Access automatically adjust the
size of the font so that every field fits.
Creating a Report in a design view
1. In a database window, click the reports
card then new
2. In the new report dialog box, click
design view
3. Click the name of the table or query
you want to generate a report form
4. Click the Ok button. You will get a
report design grid where you can place
data controls.
6. From the view menu, click Field list.
7. To design the layout, drag each field from
the field list to the layout grid and drop it
where you want the data to appear.
8. Once you finish placing controls, click the
save button.
9. In the save as dialog box, enter the name of
the report and click ok
10. To view the report click the print preview
button alternatively click print preview
from the file menu.
Modify a report layout
To modify header and footers
1. Open the report in the design view
2. Click the report header or footer you want to
modify
3. Make the necessarychanges and then click modify.
4. Click the print preview button to view the changes
How to add more controlsonto the report
1. Open a report in design view
2. Display the field list by clicking the field list
button or using the view
3. Select one or more fields in the field list and
drag viewto the report design viewgrid
How to resize or move a control
1. Click the control to select it. Position
the mouse pointer on the place
holder until the mouse pointer
changes to a double sided arrow.
2. Drag the pointer to resize the
control.
3. To move acontrol, select it and place
the mouse pointer on the place
holder until it changes to a hand
then drag.
Printing the reports
1. Before printing, you should set the page
options i.e: Margins, paper size and
orientations
2. Open the database that contains the report
you want to print
3. Click the reports tab, select the report you
want to print, and then click the preview
button.
4. On the file menu click print.
5. Set the printer options i.e:the printer type,
print range and number of copies
6. Click Ok to print.