0% found this document useful (0 votes)
14 views50 pages

Database

The document provides an overview of Microsoft Access, detailing its purpose as a database management system for organizing and managing information. It explains key components such as tables, forms, reports, and queries, along with instructions for creating databases, adding records, and establishing relationships between tables. Additionally, it includes practical exercises for creating a sample database and entering data.
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)
14 views50 pages

Database

The document provides an overview of Microsoft Access, detailing its purpose as a database management system for organizing and managing information. It explains key components such as tables, forms, reports, and queries, along with instructions for creating databases, adding records, and establishing relationships between tables. Additionally, it includes practical exercises for creating a sample database and entering data.
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/ 50

SONGEA VTC

2.3. Microsoft Access


(Database)
INTRODUCTION
Microsoft Access is a basic program that is used for creating Databases that allows
users to store, organize and manage information for reference, reporting, and analysis.
A Database (DB)
A database is a collection of information that is organized so that it can easily be
accessed, managed, and updated.
For example, A College can use a Database to store information about the students or
teachers.
A database management system is designed to allow the definition, creation,
querying, update, and administration of databases.
Examples of Database Management System Software.
1. Microsoft Access
2. MySQL
3. Microsoft SQL Server
4. Oracle
CREATING A NEW DATABASE IN MICROSOFT ACCESS
 Click the start key
 Search for ms. access
MAIN PART ACCESS DATABASE
ACCESS DATABASE OBJECTS
These are also referred to as Parts of Access Database.
1. Tables- used to store the data into column (field) and Row (record)

 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

NB: To delete a query:


 Ensure that the query is not open in design or datasheet
view
 Highlight it from the database window by clicking on it
 Press the ‘Delete’ key
 Confirm that you want to delete the query when
prompted
Deleting a query has no effect on the data stored in the
table(s) upon which it is based.
How to Query a single table.
Using Query Designer:
i. Click the Create tab, and in the Queries group,click
Query Design.
i. In the Show Table dialog box, click the table you want
to use, click Add, and then click Close to close the
dialog box.
ii. In the table, double-click the fields you want to use in
the query.
 Notice that the fields appear in the grid at the bottom of the
designer.
 You can also drag fields from the table to an empty column
in the grid.
i. On the Design tab, in the Results group, click Run.
ii. The query loads the data into a datasheet.
iii. Press CTRL+S to save the query, and in the Save As
dialog box, enter a name.
How to make a query ask for input.
1. Open the query in Design view.
2. In the design grid (the lower part of the
designer), click the Criteria row in the column to
which you want to add your criteria.
 For example, you'd add BETWEEN [Start Date] AND
[End Date] to the Criteria row of a Date/Time field.
3. Press CTRL+S to save your changes.
4. On the Design tab, in the Results group, click
Run.
5. In the first Enter Parameter Value dialog box,
enter a starting value and click OK.
6. In the second Enter Parameter Value dialog box,
enter an ending valueand click OK.
How to add a calculated field to a query.
1. Open the query in Designview.
2. In the design grid, go to the first blank
column, click the Field row, and enter your
formula or expression.
 For example:
Retire_Date:
DateAdd('yyyy',5,[Acquired_Date]).
Press CTRL+S to save your changes.
3. On the Design tab, in the Results group,
click Run.
How to retrieve Specific Records.
 You can, specify which records you
wish to retrieve.
 For example, you can retrieve :
 Only those students who live in
DE,
 Only the student whosestudent
number is 5,
 Only those students whose birth
date is 2/16/88.
 Use logical operators such as = (equal),
<> (not equal), > (greater than), or <
(less than) to restrict the records you
retrieve.
 For example, if you only want to
display students who live in DE, enter
= "DE" in the State column on the
Criteria line.
 Access will only retrieve recordswhere
the value in the State column is equal
to DE.
 How to apply multiple criteria:
1. Open a table or query in Query Design view.
2. Choose the field names you wantto retrieve
in the order you want to retrieve them.
3. Choose the field names you want to sort by
in the order you want to sort.
4. Enter your selection criteria on the Criteria
line and the Or line, as needed.
5. Deselect the Show button for columnsyou
do not want to display.
6. Click the Run button. Access retrieves the
columns you chose and displays the rows in
the order you specified.
How to Create a Query That Uses Two or More
Tables.
 To create a query that pulls the data from
multiple tables or queries.
 First create a relationship.
 To create a query that uses two or more tables:
1. Open the tables and/or queries you want to
use in Query Design view.
2. Create relationship.
3. Choose the field names you wantto retrieve
in the order you want to retrieve them.
4. Enter your selection criteria, if necessary.
5. Deselect the Show button for columns you do
not want to display .
6. Click the Run button.
 Access retrieves the columns you chose
and displays the rows in the order you
specified.
Save a Query.
 To save a query:
1. Click the Save button on the Quick Access
toolbar.
 Access saves the query unless you are saving
for the first time.
 If you are saving for the first time, the Save
As dialog box appears.
2. Type the name you want to give your query.
3. Click OK. Access saves the query. You can now
access the query by using the Navigation pane.
Exercise database.
1. Create a database called Travellers
2. Create the following tables in the database.
3. Set any other properties that you want for your field for data automation.
Drivers SHIFTS
Fields Data type Fields Data type
Drivers_ID Number Shifts_ID Number
FirstName Text Drivers_ID Number
LastName Text Vehicle_ID Number
Address Text Route_No Text
Date_Of_Birth Datetime Shift_Name Text
Hire_Date Date/Time
Salary Currency
VEHICLES ROUTES
Fields Data type Fields Data type
Vehicle_ID Number Route_No Text
Reg_No Text Distance Integer
Capacity Number Fare Currency
Make Text Destination Text
Type Text
Date_Acquired Date/Time

4. Define the appropriate relationships for your tables.


1. Enter The Information below in your tables already designed

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.

Shift Drivers_I Route


Shift Vehicle_ID
s_ID D _No
1 1 290A DAY 2
2 5 519 NIGHT 3
3 8 514B AFTERNOON 6
4 3 514A MORNING 7
5 7 1011A NIGHT 1
6 10 305D DAY 5
7 6 290B NIGHT 4
9 4 609C DAY 9
10 11 609A NIGHT 14
11 2 609B NIGHT 15
12 9 1012A DAY 16
QUESTION
1. Create the relation ship for above tables
2. Create a form for each table
3. Create a report for each table
4. Create a query to:
CREATING TOTAL QUERIES
Sometimes, you may want a query to summarize the information in a table without
giving details on each record.
For example, as a shopkeeper you may want to find out the total number of each
product you stock. You will need to create a query that groups this information
accordingly and calculates the required totals.
In the Query window, click the Totals button, or choose Totals from the
View menu.
1. The Total row appears in the grid. The words ‘Group by’ appear under
each field selected in the Query.
2. When designing a total query, the fields to be used for grouping and
the fields to be used for totals (calculations) need to be specified.
 For fields to be used for Grouping, select ‘Group by’ in the Total
Row.
 For fields to be used for Totals, select a type of calculation e.g.
Count, Sum or Average from the drop-down list in the Total row.
(See the table below for Types of Totals possible)
 Run the query to view the results.
TYPES OF TOTALS
NAME CALCULATES:
Sum The total values in a field
Avg The average of values in a field

Count The number of values in a field


Max The highest value in a field.
StDev The std deviation of values in a field
Min The lowest value in a field
Var The variance of values in a field
First The field value from the first record in a table or query
Last The field value from the last record in a table or query.
Exercise
1. Create database Q1with the following tables and implement the accompanying conditions.

NAME OWNER SPECIES SEX BIRTH DEATH


Fluffy Harold cat f 1993-02-04
Claws Gwen cat m 1994-03-17
Buffy Harold dog f 1989-05-13
Fang Benny dog m 1990-08-27
Bowser Diane dog m 1989-08-31 1995-07-29
Chirpy Gwen bird f 1998-09-11
Whistler Gwen bird 1997-12-09
Slim Benny snake m 1996-04-29
a.The table should not allow a user to enter a date of
birth that is earlier than the year 1980
b.Sort the data by the field “birth” in ascending order
c.Create a query that will show us only the following
species of animals:
i. dogs only
ii. cats only
iii. all the male dogs
iv. all the female animals
v. all animals whose owner is Harold
vi. all animals whose owner is Gwen
vii. all animals whose owner is either Benny or
Harold
Use the Report Button.
 The Report button creates a simple report that lists the
records in the selected table or query in a columnarformat.
How to use the Report button:
1. Open the Navigation pane.
2. Click the table or query on which you want to base
yourreport.
3. Activate the Create tab.
4. Click the Report button in the Reports group.
 Access creates your report and displays your
report in Layout view.
 You can modify the report.

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.

You might also like